Esempio n. 1
0
int
kperf_kdebug_set_filter(user_addr_t user_filter, uint32_t user_size)
{
	uint32_t n_debugids_provided = 0;
	int err = 0;

	if ((err = kperf_init())) {
		return err;
	}

	/* detect disabling the filter completely */
	if (user_filter == USER_ADDR_NULL || user_size == 0) {
		bzero(kperf_kdebug_filter, sizeof(*kperf_kdebug_filter));
		goto out;
	}

	n_debugids_provided = (uint32_t)KPERF_KDEBUG_N_DEBUGIDS(user_size);

	if ((err = kperf_kdebug_set_n_debugids(n_debugids_provided))) {
		goto out;
	}

	if ((err = copyin(user_filter, (char *)kperf_kdebug_filter,
	                  KPERF_KDEBUG_FILTER_SIZE(n_debugids_provided))))
	{
		bzero(kperf_kdebug_filter, sizeof(*kperf_kdebug_filter));
		goto out;
	}

out:
	kperf_kdebug_update();

	return err;
}
Esempio n. 2
0
int
kperf_action_set_count(unsigned count)
{
	struct action *new_actionv = NULL, *old_actionv = NULL;
	unsigned old_count;

	/* easy no-op */
	if( count == actionc )
		return 0;

	/* TODO: allow shrinking? */
	if( count < actionc )
		return EINVAL;

	/* cap it for good measure */
	if( count > ACTION_MAX )
		return EINVAL;

	/* creating the action arror for the first time. create a few
	 * more things, too.
	 */
       	if( actionc == 0 )
	{
		int r;
		r = kperf_init();

		if( r != 0 )
			return r;
	}

	/* create a new array */
	new_actionv = kalloc( count * sizeof(*new_actionv) );
	if( new_actionv == NULL )
		return ENOMEM;

	old_actionv = actionv;
	old_count = actionc;

	if( old_actionv != NULL )
		bcopy( actionv, new_actionv, actionc * sizeof(*actionv) );

	bzero( &new_actionv[actionc], (count - old_count) * sizeof(*actionv) );

	actionv = new_actionv;
	actionc = count;

	if( old_actionv != NULL )
		kfree( old_actionv, old_count * sizeof(*actionv) );

	printf( "kperf: done the alloc\n" );

	return 0;
}
Esempio n. 3
0
void
kperf_kdebug_reset(void)
{
	int err;

	if ((err = kperf_init())) {
		return;
	}

	kperf_kdebug_action = 0;
	bzero(kperf_kdebug_filter, sizeof(*kperf_kdebug_filter));
	kperf_kdebug_update();
}
Esempio n. 4
0
uint32_t
kperf_kdebug_get_filter(struct kperf_kdebug_filter **filter)
{
	int err;

	if ((err = kperf_init())) {
		return 0;
	}

	assert(filter != NULL);

	*filter = kperf_kdebug_filter;
	return kperf_kdebug_filter->n_debugids;
}
Esempio n. 5
0
static void
kperf_kdebug_update(void)
{
	int err;

	if ((err = kperf_init())) {
		return;
	}

	if (kperf_kdebug_action != 0 &&
	    kperf_kdebug_filter->n_debugids != 0)
	{
		kperf_kdebug_active = TRUE;
	} else {
		kperf_kdebug_active = FALSE;
	}
}
Esempio n. 6
0
int
kperf_kdebug_set_n_debugids(uint32_t n_debugids_in)
{
	int err;

	if ((err = kperf_init())) {
		return EINVAL;
	}

	if (n_debugids_in > KPERF_KDEBUG_DEBUGIDS_MAX) {
		return EINVAL;
	}

	kperf_kdebug_filter->n_debugids = n_debugids_in;

	return 0;
}
Esempio n. 7
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;
}
Esempio n. 8
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;
}