6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Copyright 2014 Igor Kozhukhov <ikozhukhov@gmail.com>.
26 * Copyright 2017 RackTop Systems.
27 * Copyright 2019 Joyent, Inc.
28 */
29
30 #ifndef _SYS_CPUVAR_H
31 #define _SYS_CPUVAR_H
32
33 #include <sys/thread.h>
34 #include <sys/sysinfo.h> /* has cpu_stat_t definition */
35 #include <sys/disp.h>
36 #include <sys/processor.h>
37 #include <sys/kcpc.h> /* has kcpc_ctx_t definition */
38
39 #include <sys/loadavg.h>
40 #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
41 #include <sys/machcpuvar.h>
42 #endif
43
44 #include <sys/types.h>
45 #include <sys/file.h>
512 extern cpu_t *cpu_active; /* list of active CPUs */
513 extern cpuset_t cpu_active_set; /* cached set of active CPUs */
514 extern int ncpus; /* number of CPUs present */
515 extern int ncpus_online; /* number of CPUs not quiesced */
516 extern int max_ncpus; /* max present before ncpus is known */
517 extern int boot_max_ncpus; /* like max_ncpus but for real */
518 extern int boot_ncpus; /* # cpus present @ boot */
519 extern processorid_t max_cpuid; /* maximum CPU number */
520 extern struct cpu *cpu_inmotion; /* offline or partition move target */
521 extern cpu_t *clock_cpu_list;
522 extern processorid_t max_cpu_seqid_ever; /* maximum seqid ever given */
523
524 #if defined(__i386) || defined(__amd64)
525 extern struct cpu *curcpup(void);
526 #define CPU (curcpup()) /* Pointer to current CPU */
527 #else
528 #define CPU (curthread->t_cpu) /* Pointer to current CPU */
529 #endif
530
531 /*
532 * CPU_CURRENT indicates to thread_affinity_set to use CPU->cpu_id
533 * as the target and to grab cpu_lock instead of requiring the caller
534 * to grab it.
535 */
536 #define CPU_CURRENT -3
537
538 /*
539 * Per-CPU statistics
540 *
541 * cpu_stats_t contains numerous system and VM-related statistics, in the form
542 * of gauges or monotonically-increasing event occurrence counts.
543 */
544
545 #define CPU_STATS_ENTER_K() kpreempt_disable()
546 #define CPU_STATS_EXIT_K() kpreempt_enable()
547
548 #define CPU_STATS_ADD_K(class, stat, amount) \
549 { kpreempt_disable(); /* keep from switching CPUs */\
550 CPU_STATS_ADDQ(CPU, class, stat, amount); \
551 kpreempt_enable(); \
552 }
553
554 #define CPU_STATS_ADDQ(cp, class, stat, amount) { \
555 extern void __dtrace_probe___cpu_##class##info_##stat(uint_t, \
556 uint64_t *, cpu_t *); \
557 uint64_t *stataddr = &((cp)->cpu_stats.class.stat); \
558 __dtrace_probe___cpu_##class##info_##stat((amount), \
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2012 by Delphix. All rights reserved.
25 * Copyright 2014 Igor Kozhukhov <ikozhukhov@gmail.com>.
26 * Copyright 2018 Joyent, Inc.
27 * Copyright 2017 RackTop Systems.
28 * Copyright 2019 Joyent, Inc.
29 */
30
31 #ifndef _SYS_CPUVAR_H
32 #define _SYS_CPUVAR_H
33
34 #include <sys/thread.h>
35 #include <sys/sysinfo.h> /* has cpu_stat_t definition */
36 #include <sys/disp.h>
37 #include <sys/processor.h>
38 #include <sys/kcpc.h> /* has kcpc_ctx_t definition */
39
40 #include <sys/loadavg.h>
41 #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP)
42 #include <sys/machcpuvar.h>
43 #endif
44
45 #include <sys/types.h>
46 #include <sys/file.h>
513 extern cpu_t *cpu_active; /* list of active CPUs */
514 extern cpuset_t cpu_active_set; /* cached set of active CPUs */
515 extern int ncpus; /* number of CPUs present */
516 extern int ncpus_online; /* number of CPUs not quiesced */
517 extern int max_ncpus; /* max present before ncpus is known */
518 extern int boot_max_ncpus; /* like max_ncpus but for real */
519 extern int boot_ncpus; /* # cpus present @ boot */
520 extern processorid_t max_cpuid; /* maximum CPU number */
521 extern struct cpu *cpu_inmotion; /* offline or partition move target */
522 extern cpu_t *clock_cpu_list;
523 extern processorid_t max_cpu_seqid_ever; /* maximum seqid ever given */
524
525 #if defined(__i386) || defined(__amd64)
526 extern struct cpu *curcpup(void);
527 #define CPU (curcpup()) /* Pointer to current CPU */
528 #else
529 #define CPU (curthread->t_cpu) /* Pointer to current CPU */
530 #endif
531
532 /*
533 * CPU_CURRENT indicates to thread_affinity_set() to use whatever curthread's
534 * current CPU is; holding cpu_lock is not required.
535 */
536 #define CPU_CURRENT -3
537
538 /*
539 * CPU_BEST can be used by thread_affinity_set() callers to set affinity to a
540 * good CPU (in particular, an ht_acquire()-friendly choice); holding cpu_lock
541 * is not required.
542 */
543 #define CPU_BEST -4
544
545 /*
546 * Per-CPU statistics
547 *
548 * cpu_stats_t contains numerous system and VM-related statistics, in the form
549 * of gauges or monotonically-increasing event occurrence counts.
550 */
551
552 #define CPU_STATS_ENTER_K() kpreempt_disable()
553 #define CPU_STATS_EXIT_K() kpreempt_enable()
554
555 #define CPU_STATS_ADD_K(class, stat, amount) \
556 { kpreempt_disable(); /* keep from switching CPUs */\
557 CPU_STATS_ADDQ(CPU, class, stat, amount); \
558 kpreempt_enable(); \
559 }
560
561 #define CPU_STATS_ADDQ(cp, class, stat, amount) { \
562 extern void __dtrace_probe___cpu_##class##info_##stat(uint_t, \
563 uint64_t *, cpu_t *); \
564 uint64_t *stataddr = &((cp)->cpu_stats.class.stat); \
565 __dtrace_probe___cpu_##class##info_##stat((amount), \
|