-Wl,option
Pass option as an option to the linker. If option contains commas, it is
split into multiple options at the commas. You can use this syntax to pass
an argument to the option. For example, -Wl,-Map,output.map passes -Map output.map
to the linker. When using the GNU linker, you can also get the same effect with
-Wl,-Map=output.map.
下面是man ld分别对-Bstatic和-Bdynamic的描述,
12345678910111213141516
-Bdynamic
-dy
-call_shared
Link against dynamic libraries. You may use this option multiple times on the
command line: it affects library searching for -l options which follow it.
-Bstatic
-dn
-non_shared
-static
Do not link against shared libraries. You may use this option multiple times on
the command line: it affects library searching for -l options which follow it.
This option also implies --unresolved-symbols=report-all. This option can be
used with -shared. Doing so means that a shared library is being created but
that all of the library's external references must be resolved by pulling in
entries from static libraries.
I noticed that a little test program which calls nanosleep is showing a huge difference in CPU usage when run on Linux machines with a kernel newer than 2.6.22.
12345678910111213
#include <time.h>
int main (void)
{
struct timespec sleepTime;
struct timespec returnTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = 1000;
while (1)
{
nanosleep(&sleepTime, &returnTime); // usleep(1); 同样异常
}
return 0;
}
(Yes, I realise this program does nothing)
If I compile this and run it on an openSUSE 10.3 machine (2.6.22.19-0.2-default), the program does not even show up on the process list generated by “top”, indicating to me that it is using very little CPU time. If I run it on an openSUSE 11.1 machine (2.6.27.23-0.1-default), top shows the program taking 40% of the CPU time. Running on Fedora 9 (2.6.25-14.fc9.i686) and Fedora 10 also showed the same high CPU usage in “top”.
Has there been a change in the kernel that affects this?
Answers
This is due to the introduction of NO_HZ into the mainline scheduler.
Previously, your 1,000 ns sleep was usually sleeping for a whole tick - 1,000,000 ns. Now, when the machine is otherwise idle, it’s actually only sleeping for what you asked for. So it’s running the while() loop and syscall around 1,000 times more frequently - hence a lot more CPU usage. If you increase tv_nsec you should see a reduction in the CPU usage.