FreeBSD/sys/kern/kern_cpu.c
/*
 * Create levels for an array of absolute settings and insert them in
 * sorted order in the specified list.
 */
Create levels for an array of absolute settings and insert them in
sorted order in the specified list.
Create levels for an array of absolute settings and insert them in sorted order in the specified list .
static int
cpufreq_insert_abs(struct cpufreq_softc *sc, struct cf_setting *sets,
    int count)
{
	struct cf_level_lst *list;
	struct cf_level *level, *search;
	int i;
	CF_MTX_ASSERT(&sc->lock);
	list = &sc->all_levels;
	for (i = 0; i < count; i++) {
		level = malloc(sizeof(*level), M_TEMP, M_NOWAIT | M_ZERO);
		if (level == NULL)
			return (ENOMEM);
		level->abs_set = sets[i];
		level->total_set = sets[i];
		level->total_set.dev = NULL;
		sc->all_count++;
		if (TAILQ_EMPTY(list)) {
			CF_DEBUG("adding abs setting %d at head\n",
			    sets[i].freq);
			TAILQ_INSERT_HEAD(list, level, link);
			continue;
		}
		TAILQ_FOREACH_REVERSE(search, list, cf_level_lst, link) {
			if (sets[i].freq <= search->total_set.freq) {
				CF_DEBUG("adding abs setting %d after %d\n",
				    sets[i].freq, search->total_set.freq);
				TAILQ_INSERT_AFTER(list, search, level, link);
				break;
			}
		}
	}
	return (0);
}
static int cpufreq_insert_abs ( struct cpufreq_softc * sc , struct cf_setting * sets , int count ) { struct cf_level_lst * list ; struct cf_level * level , * search ; int i ; CF_MTX_ASSERT ( & sc -> lock ) ; list = & sc -> all_levels ; for ( i = 0 ; i < count ; i ++ ) { level = malloc ( sizeof ( * level ) , M_TEMP , M_NOWAIT | M_ZERO ) ; if ( level == NULL ) return ( ENOMEM ) ; level -> abs_set = sets [ i ] ; level -> total_set = sets [ i ] ; level -> total_set . dev = NULL ; sc -> all_count ++ ; if ( TAILQ_EMPTY ( list ) ) { CF_DEBUG ( " \n " , sets [ i ] . freq ) ; TAILQ_INSERT_HEAD ( list , level , link ) ; continue ; } TAILQ_FOREACH_REVERSE ( search , list , cf_level_lst , link ) { if ( sets [ i ] . freq <= search -> total_set . freq ) { CF_DEBUG ( " \n " , sets [ i ] . freq , search -> total_set . freq ) ; TAILQ_INSERT_AFTER ( list , search , level , link ) ; break ; } } } return ( 0 ) ; }
Create levels for an array of absolute settings and insert them in
 sorted order in the specified list.
Create levels for an array of absolute settings and insert them in sorted order in the specified list .