* sysdeps/unix/bsd/times.c: Reorder includes and add <time.h>.
(timeval_to_clock_t): Add clk_tck argument and use that instead of
CLK_TCK.
(__times): Use __getclktck to get the number of clock ticks per
second and use its return value instead of CLK_TCK.
2001-02-10 Mark Kettenis <kettenis@gnu.org>
+2001-02-10 Mark Kettenis <kettenis@gnu.org>
+
+ * sysdeps/unix/bsd/times.c: Reorder includes and add <time.h>.
+ (timeval_to_clock_t): Add clk_tck argument and use that instead of
+ CLK_TCK.
+ (__times): Use __getclktck to get the number of clock ticks per
+ second and use its return value instead of CLK_TCK.
+
2001-02-10 Mark Kettenis <kettenis@gnu.org>
* sysdeps/unix/bsd/bsd4.4/bits/sockaddr.h (_HAVE_SA_LEN): Define.
CPU scheduling is a complex issue and different systems do it in wildly
different ways. New ideas continually develop and find their way into
the intricacies of the various systems' scheduling algorithms. This
-section discusses the general concepts, some specifics of systems
+section discusses the general concepts, some specifics of systems
that commonly use the GNU C library, and some standards.
For simplicity, we talk about CPU contention as if there is only one CPU
One thing you must keep in mind when designing real time applications is
that having higher absolute priority than any other process doesn't
guarantee the process can run continuously. Two things that can wreck a
-good CPU run are interrupts and page faults.
+good CPU run are interrupts and page faults.
Interrupt handlers live in that limbo between processes. The CPU is
executing instructions, but they aren't part of any process. An
the decision is much simpler, and is described in @ref{Absolute
Priority}.
-Each process has a scheduling policy. For processes with absolute
+Each process has a scheduling policy. For processes with absolute
priority other than zero, there are two available:
@enumerate
@item SCHED_OTHER
Traditional Scheduling
@item SCHED_FIFO
-First In First Out
+First In First Out
@item SCHED_RR
Round Robin
@end table
@comment sched.h
@comment POSIX
-@deftypefun int sched_set_priority_max (int *@var{policy});
+@deftypefun int sched_get_priority_max (int *@var{policy});
This function returns the highest absolute priority value that is
allowable for a process that with scheduling policy @var{policy}.
@comment POSIX
@deftypefun int sched_rr_get_interval (pid_t @var{pid}, struct timespec *@var{interval})
-This function returns the length of the quantum (time slice) used with
+This function returns the length of the quantum (time slice) used with
the Round Robin scheduling policy, if it is used, for the process with
Process ID @var{pid}.
-It returns the length of time as @var{interval}.
+It returns the length of time as @var{interval}.
@c We need a cross-reference to where timespec is explained. But that
@c section doesn't exist yet, and the time chapter needs to be slightly
@c reorganized so there is a place to put it (which will be right next
In addition to its absolute priority of zero, every process has another
priority, which we will refer to as "dynamic priority" because it changes
-over time. The dynamic priority is meaningless for processes with
+over time. The dynamic priority is meaningless for processes with
an absolute priority higher than zero.
The dynamic priority sometimes determines who gets the next turn on the
privileged process can lower its nice value. A privileged process can
also raise or lower another process' nice value.
-GNU C Library functions for getting and setting nice values are described in
+GNU C Library functions for getting and setting nice values are described in
@xref{Traditional Scheduling Functions}.
@node Traditional Scheduling Functions
@}
@end smallexample
@end deftypefun
-
located byte, or a null pointer if no match was found.
@end deftypefun
+@comment string.h
+@comment GNU
+@deftypefun {void *} rawmemchr (const void *@var{block}, int @var{c})
+Often the @code{memchr} function is used with the knowledge that the
+byte @var{c} is available in the memory block specified by the
+parameters. But this means that the @var{size} parameter is not really
+needed and that the tests performed with it at runtime (to check whether
+the end of the block is reached) are not needed.
+
+The @code{rawmemchr} function exists for just this situation which is
+surprisingly frequent. The interface is similar to @code{memchr} except
+that the @var{size} parameter is missing. The function will look beyond
+the end of the block pointed to by @var{block} in case the programmer
+made in error in assuming that the byte @var{c} is present in the block.
+In this case the result is unspecified. Otherwise the return value is a
+pointer to the located byte.
+
+This function is of special interest when looking for the end of a
+string. Since all strings are terminated by a null byte a call like
+
+@smallexample
+ rawmemchr (str, '\0')
+@end smallexample
+
+will never go beyond the end of the string.
+
+This function is a GNU extension.
+@end deftypefun
+
@comment string.h
@comment GNU
@deftypefun {void *} memrchr (const void *@var{block}, int @var{c}, size_t @var{size})
@end deftypefun
@comment string.h
-@comment ???
+@comment GNU
@deftypefun {char *} strchrnul (const char *@var{string}, int @var{c})
@code{strchrnul} is the same as @code{strchr} except that if it does
not find the character, it returns a pointer to string's terminating
@comment unistd.h
@comment ???
-@deftypefun int setdomainnname (const char *@var{name}, size_t @var{length})
+@deftypefun int setdomainname (const char *@var{name}, size_t @var{length})
@cindex NIS domain name
@cindex YP domain name
-/* Copyright (C) 1991, 92, 93, 95, 96, 97, 98 Free Software Foundation, Inc.
+/* Copyright (C) 1991,92,93,95,96,97,1998,2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
#include <errno.h>
#include <stddef.h>
+#include <sys/resource.h>
#include <sys/times.h>
#include <sys/time.h>
-#include <sys/resource.h>
+#include <time.h>
/* Time the program started. */
extern time_t _posix_start_time;
-#ifdef __GNUC__
+#ifdef __GNUC__
__inline
#endif
static clock_t
-timeval_to_clock_t (const struct timeval *tv)
+timeval_to_clock_t (const struct timeval *tv, clock_t clk_tck)
{
- return (clock_t) ((tv->tv_sec * CLK_TCK) +
- (tv->tv_usec * CLK_TCK / 1000000L));
+ return (clock_t) ((tv->tv_sec * clk_tck) +
+ (tv->tv_usec * clk_tck / 1000000L));
}
/* Store the CPU time used by this process and all its
struct tms *buffer;
{
struct rusage usage;
+ clock_t clk_tck;
if (buffer == NULL)
{
return (clock_t) -1;
}
+ clk_tck = __getclktck ();
+
if (__getrusage (RUSAGE_SELF, &usage) < 0)
return (clock_t) -1;
- buffer->tms_utime = (clock_t) timeval_to_clock_t (&usage.ru_utime);
- buffer->tms_stime = (clock_t) timeval_to_clock_t (&usage.ru_stime);
+ buffer->tms_utime = (clock_t) timeval_to_clock_t (&usage.ru_utime, clk_tck);
+ buffer->tms_stime = (clock_t) timeval_to_clock_t (&usage.ru_stime, clk_tck);
if (__getrusage (RUSAGE_CHILDREN, &usage) < 0)
return (clock_t) -1;
- buffer->tms_cutime = (clock_t) timeval_to_clock_t (&usage.ru_utime);
- buffer->tms_cstime = (clock_t) timeval_to_clock_t (&usage.ru_stime);
+ buffer->tms_cutime = (clock_t) timeval_to_clock_t (&usage.ru_utime, clk_tck);
+ buffer->tms_cstime = (clock_t) timeval_to_clock_t (&usage.ru_stime, clk_tck);
- return (time ((time_t *) NULL) - _posix_start_time) * CLK_TCK;
+ return (time ((time_t *) NULL) - _posix_start_time) * clk_tck;
}
weak_alias (__times, times)