xref: /titanic_44/usr/src/uts/common/sys/cpupart.h (revision 0542eecf8a04bde577ee69151dfe367a36053e40)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e824d57fSjohnlev  * Common Development and Distribution License (the "License").
6e824d57fSjohnlev  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0542eecfSRafael Vanoni  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_SYS_CPUPART_H
267c478bd9Sstevel@tonic-gate #define	_SYS_CPUPART_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate #include <sys/processor.h>
307c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
317c478bd9Sstevel@tonic-gate #include <sys/disp.h>
327c478bd9Sstevel@tonic-gate #include <sys/pset.h>
337c478bd9Sstevel@tonic-gate #include <sys/lgrp.h>
347c478bd9Sstevel@tonic-gate #include <sys/lgrp_user.h>
35fb2f18f8Sesaxe #include <sys/pg.h>
36fb2f18f8Sesaxe #include <sys/bitset.h>
377c478bd9Sstevel@tonic-gate #include <sys/time.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef _KERNEL
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef int	cpupartid_t;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Special partition id.
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate #define	CP_DEFAULT	0
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Flags for cpupart_list()
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate #define	CP_ALL		0		/* return all cpu partitions */
567c478bd9Sstevel@tonic-gate #define	CP_NONEMPTY	1		/* return only non-empty ones */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate typedef struct cpupart {
597c478bd9Sstevel@tonic-gate 	disp_t		cp_kp_queue;	/* partition-wide kpreempt queue */
607c478bd9Sstevel@tonic-gate 	cpupartid_t	cp_id;		/* partition ID */
617c478bd9Sstevel@tonic-gate 	int		cp_ncpus;	/* number of online processors */
627c478bd9Sstevel@tonic-gate 	struct cpupart	*cp_next;	/* next partition in list */
637c478bd9Sstevel@tonic-gate 	struct cpupart	*cp_prev;	/* previous partition in list */
647c478bd9Sstevel@tonic-gate 	struct cpu	*cp_cpulist;	/* processor list */
657c478bd9Sstevel@tonic-gate 	struct kstat	*cp_kstat;	/* per-partition statistics */
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	/*
687c478bd9Sstevel@tonic-gate 	 * cp_nrunnable and cp_nrunning are used to calculate load average.
697c478bd9Sstevel@tonic-gate 	 */
707c478bd9Sstevel@tonic-gate 	uint_t		cp_nrunnable;	/* current # of runnable threads */
717c478bd9Sstevel@tonic-gate 	uint_t		cp_nrunning;	/* current # of running threads */
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 	/*
747c478bd9Sstevel@tonic-gate 	 * cp_updates, cp_nrunnable_cum, cp_nwaiting_cum, and cp_hp_avenrun
757c478bd9Sstevel@tonic-gate 	 * are used to generate kstat information on an as-needed basis.
767c478bd9Sstevel@tonic-gate 	 */
777c478bd9Sstevel@tonic-gate 	uint64_t	cp_updates;	/* number of statistics updates */
787c478bd9Sstevel@tonic-gate 	uint64_t	cp_nrunnable_cum; /* cum. # of runnable threads */
797c478bd9Sstevel@tonic-gate 	uint64_t	cp_nwaiting_cum;  /* cum. # of waiting threads */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	struct loadavg_s cp_loadavg;	/* cpupart loadavg */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate 	klgrpset_t	cp_lgrpset;	/* set of lgroups on which this */
847c478bd9Sstevel@tonic-gate 					/*    partition has cpus */
857c478bd9Sstevel@tonic-gate 	lpl_t		*cp_lgrploads;	/* table of load averages for this  */
867c478bd9Sstevel@tonic-gate 					/*    partition, indexed by lgrp ID */
877c478bd9Sstevel@tonic-gate 	int		cp_nlgrploads;	/* size of cp_lgrploads table */
887c478bd9Sstevel@tonic-gate 	uint64_t	cp_hp_avenrun[3]; /* high-precision load average */
897c478bd9Sstevel@tonic-gate 	uint_t		cp_attr;	/* bitmask of attributes */
907c478bd9Sstevel@tonic-gate 	lgrp_gen_t	cp_gen;		/* generation number */
917c478bd9Sstevel@tonic-gate 	lgrp_id_t	cp_lgrp_hint;	/* last home lgroup chosen */
92fb2f18f8Sesaxe 	bitset_t	cp_cmt_pgs;	/* CMT PGs represented */
936890d023SEric Saxe 	bitset_t	cp_haltset;	/* halted CPUs */
947c478bd9Sstevel@tonic-gate } cpupart_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate typedef struct cpupart_kstat {
977c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_updates;		/* number of updates */
987c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_runnable;		/* cum # of runnable threads */
997c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_waiting;		/* cum # waiting for I/O */
1007c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_ncpus;		/* current # of CPUs */
1017c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_1min;	/* 1-minute load average */
1027c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_5min;	/* 5-minute load average */
1037c478bd9Sstevel@tonic-gate 	kstat_named_t	cpk_avenrun_15min;	/* 15-minute load average */
1047c478bd9Sstevel@tonic-gate } cpupart_kstat_t;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Macro to obtain the maximum run priority for the global queue associated
1087c478bd9Sstevel@tonic-gate  * with given cpu partition.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	CP_MAXRUNPRI(cp)	((cp)->cp_kp_queue.disp_maxrunpri)
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * This macro is used to determine if the given thread must surrender
1147c478bd9Sstevel@tonic-gate  * CPU to higher priority runnable threads on one of its dispatch queues.
1157c478bd9Sstevel@tonic-gate  * This should really be defined in <sys/disp.h> but it is not because
1167c478bd9Sstevel@tonic-gate  * including <sys/cpupart.h> there would cause recursive includes.
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate #define	DISP_MUST_SURRENDER(t)				\
1197c478bd9Sstevel@tonic-gate 	((DISP_MAXRUNPRI(t) > DISP_PRIO(t)) ||		\
1207c478bd9Sstevel@tonic-gate 	(CP_MAXRUNPRI(t->t_cpupart) > DISP_PRIO(t)))
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate extern cpupart_t	cp_default;
1237c478bd9Sstevel@tonic-gate extern cpupart_t	*cp_list_head;
1247c478bd9Sstevel@tonic-gate extern uint_t		cp_numparts;
1257c478bd9Sstevel@tonic-gate extern uint_t		cp_numparts_nonempty;
1267c478bd9Sstevel@tonic-gate 
127*0542eecfSRafael Vanoni /*
128*0542eecfSRafael Vanoni  * Each partition contains a bitset that indicates which CPUs are halted and
129*0542eecfSRafael Vanoni  * which ones are running. Given the growing number of CPUs in current and
130*0542eecfSRafael Vanoni  * future platforms, it's important to fanout each CPU within its partition's
131*0542eecfSRafael Vanoni  * haltset to prevent contention due to false sharing. The fanout factor
132*0542eecfSRafael Vanoni  * is platform specific, and declared accordingly.
133*0542eecfSRafael Vanoni  */
134*0542eecfSRafael Vanoni extern uint_t cp_haltset_fanout;
135*0542eecfSRafael Vanoni 
1367c478bd9Sstevel@tonic-gate extern void	cpupart_initialize_default();
1377c478bd9Sstevel@tonic-gate extern cpupart_t *cpupart_find(psetid_t);
1387c478bd9Sstevel@tonic-gate extern int	cpupart_create(psetid_t *);
1397c478bd9Sstevel@tonic-gate extern int	cpupart_destroy(psetid_t);
1407c478bd9Sstevel@tonic-gate extern psetid_t	cpupart_query_cpu(cpu_t *);
1417c478bd9Sstevel@tonic-gate extern int	cpupart_attach_cpu(psetid_t, cpu_t *, int);
1427c478bd9Sstevel@tonic-gate extern int	cpupart_get_cpus(psetid_t *, processorid_t *, uint_t *);
1437c478bd9Sstevel@tonic-gate extern int	cpupart_bind_thread(kthread_id_t, psetid_t, int, void *,
1447c478bd9Sstevel@tonic-gate     void *);
1457c478bd9Sstevel@tonic-gate extern void	cpupart_kpqalloc(pri_t);
1467c478bd9Sstevel@tonic-gate extern int	cpupart_get_loadavg(psetid_t, int *, int);
1477c478bd9Sstevel@tonic-gate extern uint_t	cpupart_list(psetid_t *, uint_t, int);
1487c478bd9Sstevel@tonic-gate extern int	cpupart_setattr(psetid_t, uint_t);
1497c478bd9Sstevel@tonic-gate extern int	cpupart_getattr(psetid_t, uint_t *);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate #endif
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate #endif	/* _SYS_CPUPART_H */
158