int kperf_sampling_disable(void) { if (sampling_status != KPERF_SAMPLING_ON) { return 0; } /* mark a shutting down */ sampling_status = KPERF_SAMPLING_SHUTDOWN; /* tell timers to disable */ kperf_timer_stop(); /* mark as off */ sampling_status = KPERF_SAMPLING_OFF; kperf_lightweight_pet_active_update(); return 0; }
extern int kperf_timer_set_count(unsigned int count) { struct kperf_timer *new_timerv = NULL, *old_timerv = NULL; unsigned int old_count; if (min_period_abstime == 0) { nanoseconds_to_absolutetime(MIN_PERIOD_NS, &min_period_abstime); nanoseconds_to_absolutetime(MIN_PERIOD_BG_NS, &min_period_bg_abstime); nanoseconds_to_absolutetime(MIN_PERIOD_PET_NS, &min_period_pet_abstime); nanoseconds_to_absolutetime(MIN_PERIOD_PET_BG_NS, &min_period_pet_bg_abstime); assert(min_period_abstime > 0); } if (count == kperf_timerc) { return 0; } if (count > TIMER_MAX) { return EINVAL; } /* TODO: allow shrinking? */ if (count < kperf_timerc) { return EINVAL; } /* * Make sure kperf is initialized when creating the array for the first * time. */ if (kperf_timerc == 0) { int r; /* main kperf */ if ((r = kperf_init())) { return r; } } /* * Shut down any running timers since we will be messing with the timer * call structures. */ kperf_timer_stop(); /* create a new array */ new_timerv = kalloc_tag(count * sizeof(struct kperf_timer), VM_KERN_MEMORY_DIAG); if (new_timerv == NULL) { return ENOMEM; } old_timerv = kperf_timerv; old_count = kperf_timerc; if (old_timerv != NULL) { bcopy(kperf_timerv, new_timerv, kperf_timerc * sizeof(struct kperf_timer)); } /* zero the new entries */ bzero(&(new_timerv[kperf_timerc]), (count - old_count) * sizeof(struct kperf_timer)); /* (re-)setup the timer call info for all entries */ for (unsigned int i = 0; i < count; i++) { timer_call_setup(&(new_timerv[i].tcall), kperf_timer_handler, &(new_timerv[i])); } kperf_timerv = new_timerv; kperf_timerc = count; if (old_timerv != NULL) { kfree(old_timerv, old_count * sizeof(struct kperf_timer)); } return 0; }
extern int kperf_timer_set_count(unsigned count) { struct time_trigger *new_timerv = NULL, *old_timerv = NULL; unsigned old_count, i; /* easy no-op */ if( count == timerc ) return 0; /* TODO: allow shrinking? */ if( count < timerc ) return EINVAL; /* cap it for good measure */ if( count > TIMER_MAX ) return EINVAL; /* creating the action arror for the first time. create a few * more things, too. */ if( timerc == 0 ) { int r; /* main kperf */ r = kperf_init(); if( r ) return r; /* get the PET thread going */ r = kperf_pet_init(); if( r ) return r; } /* first shut down any running timers since we will be messing * with the timer call structures */ if( kperf_timer_stop() ) return EBUSY; /* create a new array */ new_timerv = kalloc( count * sizeof(*new_timerv) ); if( new_timerv == NULL ) return ENOMEM; old_timerv = timerv; old_count = timerc; if( old_timerv != NULL ) bcopy( timerv, new_timerv, timerc * sizeof(*timerv) ); /* zero the new entries */ bzero( &new_timerv[timerc], (count - old_count) * sizeof(*new_timerv) ); /* (re-)setup the timer call info for all entries */ for( i = 0; i < count; i++ ) setup_timer_call( &new_timerv[i] ); timerv = new_timerv; timerc = count; if( old_timerv != NULL ) kfree( old_timerv, old_count * sizeof(*timerv) ); return 0; }