mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 02:40:08 +00:00
92777700d2
* sysdeps/unix/dirstream.h: Rewritten. * sysdeps/unix/readdir.c: Rewritten. * sysdeps/unix/telldir.c: Rewritten. * sysdeps/unix/closedir.c: Use <...> instead of "..." for dirstream.h. Remove __ from DIR struct member names. * sysdeps/unix/dirfd.c: Likewise. * sysdeps/unix/seekdir.c: Likewise. * sysdeps/unix/rewinddir.c: Likewise. * sysdeps/unix/opendir.c: Likewise. Don't allocate extra space after DIR structure. * sysdeps/stub/direct.h: File removed. * sysdeps/unix/bsd/bsd4.4/direct.h: File removed. * sysdeps/unix/bsd/direct.h: File removed. * sysdeps/unix/common/direct.h: File removed. * sysdeps/unix/sysv/irix4/direct.h: File removed. * sysdeps/unix/sysv/isc3/direct.h: File removed. * sysdeps/unix/sysv/sco3.2.4/direct.h: File removed. * sysdeps/unix/sysv/sysv4/solaris2/direct.h: File removed. * sysdeps/unix/common/direntry.h: New file. * sysdeps/unix/bsd/direntry.h: New file. * sysdeps/unix/bsd/bsd4.4/direntry.h: New file. * sysdeps/unix/sysv/direntry.h: New file. * sysdeps/stub/direntry.h: New file. * dirent/dirent.h (struct dirent): Type removed. Include <direntry.h> to define it. (_D_EXACT_NAMLEN, _D_ALLOC_NAMLEN): New macros. * dirent/Makefile (headers): Add direntry.h. (distribute): Remove direct.h. * sysdeps/posix/getcwd.c: Use new macros instead of d_namlen. * dirent/scandir.c: Likewise. * io/fts.c (fts_build): Likewise. * io/ftw.c (ftw_dir): Likewise. * sysdeps/posix/ttyname.c: Likewise. * sysdeps/unix/sysv/sysv4/solaris2/syscalls.list: New file. * sysdeps/mach/hurd/profil.c (MAX_PC_SAMPLES): New macro. (collector_timeout): New static variable. (update_waiter): Actually call __task_enable_pc_sampling. Set collector_timeout based on the `tick' count returned. (profile_waiter): Use MAX_PC_SAMPLES. Set nsamples before RPC. Use collector_timeout in __mach_msg call. * gmon/Makefile (noprof): New variable containing mcount. Append profil unless it is in $(unix-syscalls). (mcount.po): Use $(noprof) for list of targets in this rule. * libc-symbols.h: Define _LIBC before #include <config.h>. Sun Feb 25 12:29:23 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu> * config.h.in [_LIBC] (HAVE_STRERROR): Define it. Protect 2nd page of #undef's for generator programs with #ifndef _LIBC. * time/zic.c, time/zdump.c, time/private.h: Updated from ADO's latest. Fri Feb 9 12:40:19 1996 Brendan Kehoe <brendan@lisa.cygnus.com> * libio/cleanup.c (_IO_cleanup_registration_needed) [!_G_HAVE_ATEXIT]: Init to NULL. * libio/filedoalloc.c (_IO_cleanup_registration_needed): Remove decl. Thu Feb 8 08:12:50 1996 Brendan Kehoe <brendan@cygnus.com> * libio/filedoalloc.c (_IO_cleanup_registration_needed): Revert previous change, since cleanup.c only defines it if _G_HAVE_ATEXIT. Wed Feb 7 15:10:17 1996 Brendan Kehoe <brendan@lisa.cygnus.com> * libio/filedoalloc.c (_IO_cleanup_registration_needed): Declare as extern. Sat Feb 24 11:34:13 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu> * sysdeps/i386/memcmp.S: Fix argument %esp offsets. * time/sys/time.h (timeradd, timersub): New macros; BSD has these.
181 lines
4.9 KiB
C
181 lines
4.9 KiB
C
/* Low-level statistical profiling support function. Mach/Hurd version.
|
||
Copyright (C) 1995, 1996 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
|
||
modify it under the terms of the GNU Library General Public License as
|
||
published by the Free Software Foundation; either version 2 of the
|
||
License, or (at your option) any later version.
|
||
|
||
The GNU C Library is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
Library General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Library General Public
|
||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||
Cambridge, MA 02139, USA. */
|
||
|
||
#include <sys/types.h>
|
||
#include <unistd.h>
|
||
#include <errno.h>
|
||
#include <hurd.h>
|
||
#include <mach/mach4.h>
|
||
#include <mach/pc_sample.h>
|
||
#include <cthreads.h>
|
||
#include <assert.h>
|
||
|
||
#define MAX_PC_SAMPLES 512 /* XXX ought to be exported in kernel hdr */
|
||
|
||
static thread_t profile_thread = MACH_PORT_NULL;
|
||
static u_short *samples;
|
||
static size_t maxsamples;
|
||
static size_t pc_offset;
|
||
static size_t sample_scale;
|
||
static sampled_pc_seqno_t seqno;
|
||
static struct mutex lock = MUTEX_INITIALIZER;
|
||
static mach_msg_timeout_t collector_timeout; /* ms between collections. */
|
||
|
||
/* Enable statistical profiling, writing samples of the PC into at most
|
||
SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling
|
||
is enabled, the system examines the user PC and increments
|
||
SAMPLE_BUFFER[((PC - OFFSET) / 2) * SCALE / 65536]. If SCALE is zero,
|
||
disable profiling. Returns zero on success, -1 on error. */
|
||
|
||
static error_t
|
||
update_waiter (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
|
||
{
|
||
error_t err;
|
||
|
||
if (profile_thread == MACH_PORT_NULL)
|
||
{
|
||
/* Set up the profiling collector thread. */
|
||
static void profile_waiter (void);
|
||
err = __thread_create (__mach_task_self (), &profile_thread);
|
||
if (! err)
|
||
err = __mach_setup_thread (__mach_task_self (), profile_thread,
|
||
&profile_waiter, NULL, NULL);
|
||
}
|
||
else
|
||
err = 0;
|
||
|
||
if (! err)
|
||
{
|
||
int tick; /* Microseconds per sample. */
|
||
err = __task_enable_pc_sampling (__mach_task_self (), &tick,
|
||
SAMPLED_PC_PERIODIC);
|
||
if (!err && sample_scale == 0)
|
||
/* Profiling was not turned on, so the collector thread was
|
||
suspended. Resume it. */
|
||
err = __thread_resume (profile_thread);
|
||
if (! err)
|
||
{
|
||
samples = sample_buffer;
|
||
maxsamples = size / sizeof *sample_buffer;
|
||
pc_offset = offset;
|
||
sample_scale = scale;
|
||
/* Calculate a good period for the collector thread. From TICK
|
||
and the kernel buffer size we get the length of time it takes
|
||
to fill the buffer; translate that to milliseconds for
|
||
mach_msg, and chop it in half for general lag factor. */
|
||
collector_timeout = MAX_PC_SAMPLES * tick / 1000 / 2;
|
||
}
|
||
}
|
||
|
||
return err;
|
||
}
|
||
|
||
int
|
||
profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
|
||
{
|
||
error_t err;
|
||
|
||
__mutex_lock (&lock);
|
||
|
||
if (scale == 0)
|
||
{
|
||
/* Disable profiling. */
|
||
int count;
|
||
__thread_suspend (profile_thread);
|
||
err = __task_disable_pc_sampling (__mach_task_self (), &count);
|
||
sample_scale = 0;
|
||
seqno = 0;
|
||
}
|
||
else
|
||
err = update_waiter (sample_buffer, size, offset, scale);
|
||
|
||
__mutex_unlock (&lock);
|
||
|
||
return err ? __hurd_fail (err) : 0;
|
||
}
|
||
|
||
static void
|
||
profile_waiter (void)
|
||
{
|
||
sampled_pc_t pc_samples[MAX_PC_SAMPLES];
|
||
mach_msg_type_number_t nsamples, i;
|
||
mach_port_t rcv = __mach_reply_port ();
|
||
mach_msg_header_t msg;
|
||
error_t err;
|
||
|
||
while (1)
|
||
{
|
||
__mutex_lock (&lock);
|
||
|
||
nsamples = sizeof pc_samples / sizeof pc_samples[0];
|
||
err = __task_get_sampled_pcs (__mach_task_self (), &seqno,
|
||
pc_samples, &nsamples);
|
||
assert_perror (err);
|
||
|
||
for (i = 0; i < nsamples; ++i)
|
||
{
|
||
size_t idx = (((pc_samples[i].pc - pc_offset) / 2) *
|
||
sample_scale / 65536);
|
||
if (idx < maxsamples)
|
||
++samples[idx];
|
||
}
|
||
|
||
__vm_deallocate (__mach_task_self (),
|
||
(vm_address_t) pc_samples,
|
||
nsamples * sizeof *pc_samples);
|
||
|
||
__mutex_unlock (&lock);
|
||
|
||
__mach_msg (&msg, MACH_RCV_MSG|MACH_RCV_TIMEOUT, 0, sizeof msg,
|
||
rcv, collector_timeout, MACH_PORT_NULL);
|
||
}
|
||
}
|
||
|
||
data_set_element (_hurd_fork_locks, lock);
|
||
|
||
static void
|
||
fork_profil (void)
|
||
{
|
||
u_short *sb;
|
||
size_t n, o, ss;
|
||
error_t err;
|
||
|
||
if (profile_thread != MACH_PORT_NULL)
|
||
{
|
||
__mach_port_deallocate (__mach_task_self (), profile_thread);
|
||
profile_thread = MACH_PORT_NULL;
|
||
}
|
||
|
||
sb = samples;
|
||
samples = NULL;
|
||
n = maxsamples;
|
||
maxsamples = 0;
|
||
o = pc_offset;
|
||
pc_offset = 0;
|
||
ss = sample_scale;
|
||
sample_scale = 0;
|
||
|
||
if (ss != 0)
|
||
{
|
||
err = update_waiter (sb, n * sizeof *sb, o, ss);
|
||
assert_perror (err);
|
||
}
|
||
}
|
||
text_set_element (_hurd_fork_child_hook, fork_profil);
|