diff options
author | Vladimir Mezentsev <vladimir.mezentsev@oracle.com> | 2024-05-20 18:48:07 -0700 |
---|---|---|
committer | Vladimir Mezentsev <vladimir.mezentsev@oracle.com> | 2024-05-21 19:54:56 -0700 |
commit | a3e8656c02f717d48051e1dd8de4cdc89eb3f373 (patch) | |
tree | 719c85b7a69ccd37f4f1c2756d20600ef90c4881 | |
parent | 9f8b42c871ac1b75a4270378e33fd1b1fba95f84 (diff) | |
download | binutils-a3e8656c02f717d48051e1dd8de4cdc89eb3f373.zip binutils-a3e8656c02f717d48051e1dd8de4cdc89eb3f373.tar.gz binutils-a3e8656c02f717d48051e1dd8de4cdc89eb3f373.tar.bz2 |
gprofng: remove memset() in libcollector
ChangeLog
2024-05-20 Vladimir Mezentsev <vladimir.mezentsev@oracle.com>
* libcollector/collector.c: Use static initialization instead of memset.
* libcollector/dispatcher.c: Likewise.
* libcollector/hwprofile.c: Likewise.
* libcollector/jprofile.c: Likewise.
* libcollector/profile.c: Likewise.
* libcollector/synctrace.c: Likewise.
-rw-r--r-- | gprofng/libcollector/collector.c | 10 | ||||
-rw-r--r-- | gprofng/libcollector/dispatcher.c | 7 | ||||
-rw-r--r-- | gprofng/libcollector/hwprofile.c | 12 | ||||
-rw-r--r-- | gprofng/libcollector/jprofile.c | 4 | ||||
-rw-r--r-- | gprofng/libcollector/profile.c | 7 | ||||
-rw-r--r-- | gprofng/libcollector/synctrace.c | 34 |
6 files changed, 24 insertions, 50 deletions
diff --git a/gprofng/libcollector/collector.c b/gprofng/libcollector/collector.c index 3952975..3a8f27a 100644 --- a/gprofng/libcollector/collector.c +++ b/gprofng/libcollector/collector.c @@ -1344,10 +1344,9 @@ __collector_close_experiment () return; } - struct sigaction sa; - CALL_UTIL (memset)(&sa, 0, sizeof (struct sigaction)); + static struct sigaction sigaction_0 = {.sa_flags = SA_SIGINFO }; + struct sigaction sa = sigaction_0; sa.sa_sigaction = __collector_SIGCHLD_signal_handler; - sa.sa_flags = SA_SIGINFO; __collector_sigaction (SIGCHLD, &sa, &original_sigchld_sigaction); /* linetrace interposition takes care of unsetting Environment variables */ @@ -2319,7 +2318,6 @@ ovw_write () return 0; int fd; int res; - struct prusage usage; struct rusage rusage; hrtime_t hrt, delta; @@ -2335,9 +2333,9 @@ ovw_write () return ( hrt); } - CALL_UTIL (memset)(&usage, 0, sizeof (struct prusage)); + static struct prusage usage_0 = { .pr_count = 1 }; + struct prusage usage = usage_0; usage.pr_lwpid = getpid (); - usage.pr_count = 1; usage.pr_tstamp.tv_sec = hrt / NANOSEC; usage.pr_tstamp.tv_nsec = hrt % NANOSEC; usage.pr_create.tv_sec = starttime / NANOSEC; diff --git a/gprofng/libcollector/dispatcher.c b/gprofng/libcollector/dispatcher.c index d2a4ad0..8b8ad77 100644 --- a/gprofng/libcollector/dispatcher.c +++ b/gprofng/libcollector/dispatcher.c @@ -109,6 +109,7 @@ enum DISPATCH_TST = 2 /* dispatcher installed, and enabled in testing mode */ }; +static struct sigaction sigaction_0; static int dispatch_mode = DISPATCH_NYI; /* controls SIGPROF dispatching */ static int itimer_period_requested = 0; /* dispatcher itimer period */ static int itimer_period_actual = 0; /* actual dispatcher itimer period */ @@ -263,8 +264,7 @@ __collector_sigprof_install () TprintfT (DBG_LT1, "dispatcher: __collector_ext_dispatcher_install() collector_sigprof_dispatcher already installed\n"); else { - struct sigaction c_act; - CALL_UTIL (memset)(&c_act, 0, sizeof c_act); + struct sigaction c_act = sigaction_0; sigemptyset (&c_act.sa_mask); sigaddset (&c_act.sa_mask, HWCFUNCS_SIGNAL); /* block SIGEMT delivery in handler */ c_act.sa_sigaction = collector_sigprof_dispatcher; @@ -358,8 +358,7 @@ void __collector_SIGDFL_handler (int sig) { /* remove our dispatcher, replacing it with the default disposition */ - struct sigaction act; - CALL_UTIL (memset)(&act, 0, sizeof (act)); + struct sigaction act = sigaction_0; act.sa_handler = SIG_DFL; if (__collector_sigaction (sig, &act, NULL)) { diff --git a/gprofng/libcollector/hwprofile.c b/gprofng/libcollector/hwprofile.c index 364c600..cfe0d84 100644 --- a/gprofng/libcollector/hwprofile.c +++ b/gprofng/libcollector/hwprofile.c @@ -32,7 +32,6 @@ #include <signal.h> #include "gp-defs.h" -#define _STRING_H 1 /* XXX MEZ: temporary workaround */ #include "hwcdrv.h" #include "collector_module.h" #include "gp-experiment.h" @@ -409,8 +408,8 @@ hwc_initialize_handlers (void) else { /* set our signal handler */ - struct sigaction c_act; - CALL_UTIL (memset)(&c_act, 0, sizeof c_act); + static struct sigaction c_act_0 = {.sa_flags = SA_RESTART | SA_SIGINFO}; + struct sigaction c_act = c_act_0; sigemptyset (&c_act.sa_mask); sigaddset (&c_act.sa_mask, SIGPROF); /* block SIGPROF delivery in handler */ /* XXXX should probably also block sample_sig & pause_sig */ @@ -531,8 +530,9 @@ collector_record_counter_internal (ucontext_t *ucp, int timecvt, uint64_t va, uint64_t latency, uint64_t data_source) { - MHwcntr_packet pckt; - CALL_UTIL (memset)(&pckt, 0, sizeof ( MHwcntr_packet)); + static MHwcntr_packet hwc_packet_0 = {.comm.type = HW_PCKT, + .comm.tsize = sizeof (Hwcntr_packet)}; + MHwcntr_packet pckt = hwc_packet_0; pckt.comm.tstamp = time; pckt.tag = tag; if (timecvt > 1) @@ -547,8 +547,6 @@ collector_record_counter_internal (ucontext_t *ucp, int timecvt, value *= timecvt; } pckt.interval = value; - pckt.comm.type = HW_PCKT; - pckt.comm.tsize = sizeof (Hwcntr_packet); TprintfT (DBG_LT4, "hwprofile: %llu sample %lld tag %u recorded\n", (unsigned long long) time, (long long) value, tag); if (ABS_memop == ABST_NOPC) diff --git a/gprofng/libcollector/jprofile.c b/gprofng/libcollector/jprofile.c index 2cabb1a..cd498be 100644 --- a/gprofng/libcollector/jprofile.c +++ b/gprofng/libcollector/jprofile.c @@ -361,8 +361,8 @@ JVM_OnLoad (JavaVM *vm, char *options, void *reserved) err = (*jvmti)->GetPotentialCapabilities (jvmti, &cpblts); if (err == JVMTI_ERROR_NONE) { - jvmtiCapabilities cpblts_set; - CALL_UTIL (memset)(&cpblts_set, 0, sizeof (cpblts_set)); + static jvmtiCapabilities cpblts_set_0; + jvmtiCapabilities cpblts_set = cpblts_set_0; /* Add only those capabilities that are among potential ones */ cpblts_set.can_get_source_file_name = cpblts.can_get_source_file_name; diff --git a/gprofng/libcollector/profile.c b/gprofng/libcollector/profile.c index 127fd69..f654623 100644 --- a/gprofng/libcollector/profile.c +++ b/gprofng/libcollector/profile.c @@ -272,10 +272,9 @@ __collector_ext_profile_handler (siginfo_t *info, ucontext_t *context) CALL_UTIL (getcontext) (context); /* initialize dummy context */ SETFUNCTIONCONTEXT (context, &__collector_lost_profile_context); } - ClockPacket pckt; - CALL_UTIL (memset)(&pckt, 0, sizeof ( pckt)); - pckt.comm.tsize = sizeof ( pckt); - pckt.comm.type = CLOCK_TYPE; + static ClockPacket clock_pckt_0 = {.comm.type = CLOCK_TYPE, + .comm.tsize = sizeof (ClockPacket)}; + ClockPacket pckt = clock_pckt_0; pckt.lwp_id = __collector_lwp_self (); pckt.thr_id = __collector_thr_self (); pckt.cpu_id = CALL_UTIL (getcpuid)(); diff --git a/gprofng/libcollector/synctrace.c b/gprofng/libcollector/synctrace.c index a304188..2f3097f 100644 --- a/gprofng/libcollector/synctrace.c +++ b/gprofng/libcollector/synctrace.c @@ -75,6 +75,7 @@ static unsigned sync_key = COLLECTOR_TSD_INVALID_KEY; static long sync_threshold = -1; /* calibrate the value */ static int init_thread_intf_started = 0; static int init_thread_intf_finished = 0; +static Sync_packet spacket_0 = { .comm.tsize = sizeof ( Sync_packet) }; #define CHCK_NREENTRANCE(x) (!sync_native || !sync_mode || ((x) = collector_interface->getKey( sync_key )) == NULL || (*(x) != 0)) #define RECHCK_NREENTRANCE(x) (!sync_native || !sync_mode || ((x) = collector_interface->getKey( sync_key )) == NULL || (*(x) == 0)) @@ -137,15 +138,6 @@ static int (*__real_pthread_cond_timedwait_2_0) (pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) = NULL; - -static void -collector_memset (void *s, int c, size_t n) -{ - unsigned char *s1 = s; - while (n--) - *s1++ = (unsigned char) c; -} - void __collector_module_init (CollectorInterface *_collector_interface) { @@ -568,9 +560,7 @@ __collector_jsync_end (hrtime_t reqt, void *object) hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) object; @@ -600,9 +590,7 @@ gprofng_pthread_mutex_lock (int (real_func) (pthread_mutex_t *), hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mp; @@ -647,9 +635,7 @@ gprofng_pthread_cond_wait (int(real_func) (pthread_cond_t *, pthread_mutex_t *), hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mutex; @@ -697,9 +683,7 @@ gprofng_pthread_cond_timedwait (int(real_func) (pthread_cond_t *, hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) mutex; @@ -746,9 +730,7 @@ gprofng_pthread_join (int(real_func) (pthread_t, void **), hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (Vaddr_type) target_thread; @@ -793,9 +775,7 @@ gprofng_sem_wait (int (real_func) (sem_t *), sem_t *sp) hrtime_t grnt = gethrtime (); if (grnt - reqt >= sync_threshold) { - Sync_packet spacket; - collector_memset (&spacket, 0, sizeof (Sync_packet)); - spacket.comm.tsize = sizeof (Sync_packet); + Sync_packet spacket = spacket_0; spacket.comm.tstamp = grnt; spacket.requested = reqt; spacket.objp = (intptr_t) sp; |