10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5713Swesolows * Common Development and Distribution License (the "License"). 6713Swesolows * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21713Swesolows 220Sstevel@tonic-gate /* 23*12908SPavel.Tatashin@Sun.COM * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _SYS_CPUVAR_H 270Sstevel@tonic-gate #define _SYS_CPUVAR_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/thread.h> 300Sstevel@tonic-gate #include <sys/sysinfo.h> /* has cpu_stat_t definition */ 310Sstevel@tonic-gate #include <sys/disp.h> 320Sstevel@tonic-gate #include <sys/processor.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) 350Sstevel@tonic-gate #include <sys/machcpuvar.h> 360Sstevel@tonic-gate #endif 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <sys/file.h> 400Sstevel@tonic-gate #include <sys/bitmap.h> 410Sstevel@tonic-gate #include <sys/rwlock.h> 420Sstevel@tonic-gate #include <sys/msacct.h> 43713Swesolows #if defined(__GNUC__) && defined(_ASM_INLINES) && defined(_KERNEL) && \ 44713Swesolows (defined(__i386) || defined(__amd64)) 450Sstevel@tonic-gate #include <asm/cpuvar.h> 460Sstevel@tonic-gate #endif 470Sstevel@tonic-gate 480Sstevel@tonic-gate #ifdef __cplusplus 490Sstevel@tonic-gate extern "C" { 500Sstevel@tonic-gate #endif 510Sstevel@tonic-gate 520Sstevel@tonic-gate struct squeue_set_s; 530Sstevel@tonic-gate 540Sstevel@tonic-gate #define CPU_CACHE_COHERENCE_SIZE 64 550Sstevel@tonic-gate #define S_LOADAVG_SZ 11 560Sstevel@tonic-gate #define S_MOVAVG_SZ 10 570Sstevel@tonic-gate 580Sstevel@tonic-gate struct loadavg_s { 590Sstevel@tonic-gate int lg_cur; /* current loadavg entry */ 600Sstevel@tonic-gate unsigned int lg_len; /* number entries recorded */ 610Sstevel@tonic-gate hrtime_t lg_total; /* used to temporarily hold load totals */ 620Sstevel@tonic-gate hrtime_t lg_loads[S_LOADAVG_SZ]; /* table of recorded entries */ 630Sstevel@tonic-gate }; 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * For fast event tracing. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate struct ftrace_record; 690Sstevel@tonic-gate typedef struct ftrace_data { 700Sstevel@tonic-gate int ftd_state; /* ftrace flags */ 713647Sbs21162 kmutex_t ftd_unused; /* ftrace buffer lock, unused */ 720Sstevel@tonic-gate struct ftrace_record *ftd_cur; /* current record */ 730Sstevel@tonic-gate struct ftrace_record *ftd_first; /* first record */ 740Sstevel@tonic-gate struct ftrace_record *ftd_last; /* last record */ 750Sstevel@tonic-gate } ftrace_data_t; 760Sstevel@tonic-gate 770Sstevel@tonic-gate struct cyc_cpu; 780Sstevel@tonic-gate struct nvlist; 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * Per-CPU data. 822722Sjohnlev * 832722Sjohnlev * Be careful adding new members: if they are not the same in all modules (e.g. 842722Sjohnlev * change size depending on a #define), CTF uniquification can fail to work 852722Sjohnlev * properly. Furthermore, this is transitive in that it applies recursively to 862722Sjohnlev * all types pointed to by cpu_t. 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate typedef struct cpu { 890Sstevel@tonic-gate processorid_t cpu_id; /* CPU number */ 900Sstevel@tonic-gate processorid_t cpu_seqid; /* sequential CPU id (0..ncpus-1) */ 910Sstevel@tonic-gate volatile cpu_flag_t cpu_flags; /* flags indicating CPU state */ 920Sstevel@tonic-gate struct cpu *cpu_self; /* pointer to itself */ 930Sstevel@tonic-gate kthread_t *cpu_thread; /* current thread */ 940Sstevel@tonic-gate kthread_t *cpu_idle_thread; /* idle thread for this CPU */ 950Sstevel@tonic-gate kthread_t *cpu_pause_thread; /* pause thread for this CPU */ 960Sstevel@tonic-gate klwp_id_t cpu_lwp; /* current lwp (if any) */ 970Sstevel@tonic-gate klwp_id_t cpu_fpowner; /* currently loaded fpu owner */ 980Sstevel@tonic-gate struct cpupart *cpu_part; /* partition with this CPU */ 990Sstevel@tonic-gate struct lgrp_ld *cpu_lpl; /* pointer to this cpu's load */ 1000Sstevel@tonic-gate int cpu_cache_offset; /* see kmem.c for details */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Links to other CPUs. It is safe to walk these lists if 1040Sstevel@tonic-gate * one of the following is true: 1050Sstevel@tonic-gate * - cpu_lock held 1060Sstevel@tonic-gate * - preemption disabled via kpreempt_disable 1070Sstevel@tonic-gate * - PIL >= DISP_LEVEL 1080Sstevel@tonic-gate * - acting thread is an interrupt thread 1090Sstevel@tonic-gate * - all other CPUs are paused 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate struct cpu *cpu_next; /* next existing CPU */ 1120Sstevel@tonic-gate struct cpu *cpu_prev; /* prev existing CPU */ 1130Sstevel@tonic-gate struct cpu *cpu_next_onln; /* next online (enabled) CPU */ 1140Sstevel@tonic-gate struct cpu *cpu_prev_onln; /* prev online (enabled) CPU */ 1150Sstevel@tonic-gate struct cpu *cpu_next_part; /* next CPU in partition */ 1160Sstevel@tonic-gate struct cpu *cpu_prev_part; /* prev CPU in partition */ 1170Sstevel@tonic-gate struct cpu *cpu_next_lgrp; /* next CPU in latency group */ 1180Sstevel@tonic-gate struct cpu *cpu_prev_lgrp; /* prev CPU in latency group */ 1190Sstevel@tonic-gate struct cpu *cpu_next_lpl; /* next CPU in lgrp partition */ 1200Sstevel@tonic-gate struct cpu *cpu_prev_lpl; 1213434Sesaxe 1223434Sesaxe struct cpu_pg *cpu_pg; /* cpu's processor groups */ 1233434Sesaxe 1240Sstevel@tonic-gate void *cpu_reserved[4]; /* reserved for future use */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* 1270Sstevel@tonic-gate * Scheduling variables. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate disp_t *cpu_disp; /* dispatch queue data */ 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * Note that cpu_disp is set before the CPU is added to the system 1320Sstevel@tonic-gate * and is never modified. Hence, no additional locking is needed 1330Sstevel@tonic-gate * beyond what's necessary to access the cpu_t structure. 1340Sstevel@tonic-gate */ 1350Sstevel@tonic-gate char cpu_runrun; /* scheduling flag - set to preempt */ 1360Sstevel@tonic-gate char cpu_kprunrun; /* force kernel preemption */ 1370Sstevel@tonic-gate pri_t cpu_chosen_level; /* priority at which cpu */ 1380Sstevel@tonic-gate /* was chosen for scheduling */ 1390Sstevel@tonic-gate kthread_t *cpu_dispthread; /* thread selected for dispatch */ 1400Sstevel@tonic-gate disp_lock_t cpu_thread_lock; /* dispatcher lock on current thread */ 1410Sstevel@tonic-gate uint8_t cpu_disp_flags; /* flags used by dispatcher */ 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * The following field is updated when ever the cpu_dispthread 1440Sstevel@tonic-gate * changes. Also in places, where the current thread(cpu_dispthread) 1450Sstevel@tonic-gate * priority changes. This is used in disp_lowpri_cpu() 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate pri_t cpu_dispatch_pri; /* priority of cpu_dispthread */ 1480Sstevel@tonic-gate clock_t cpu_last_swtch; /* last time switched to new thread */ 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * Interrupt data. 1520Sstevel@tonic-gate */ 1530Sstevel@tonic-gate caddr_t cpu_intr_stack; /* interrupt stack */ 1540Sstevel@tonic-gate kthread_t *cpu_intr_thread; /* interrupt thread list */ 1550Sstevel@tonic-gate uint_t cpu_intr_actv; /* interrupt levels active (bitmask) */ 1560Sstevel@tonic-gate int cpu_base_spl; /* priority for highest rupt active */ 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate /* 1590Sstevel@tonic-gate * Statistics. 1600Sstevel@tonic-gate */ 1610Sstevel@tonic-gate cpu_stats_t cpu_stats; /* per-CPU statistics */ 1620Sstevel@tonic-gate struct kstat *cpu_info_kstat; /* kstat for cpu info */ 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate uintptr_t cpu_profile_pc; /* kernel PC in profile interrupt */ 1650Sstevel@tonic-gate uintptr_t cpu_profile_upc; /* user PC in profile interrupt */ 1660Sstevel@tonic-gate uintptr_t cpu_profile_pil; /* PIL when profile interrupted */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate ftrace_data_t cpu_ftrace; /* per cpu ftrace data */ 1690Sstevel@tonic-gate 17011066Srafael.vanoni@sun.com clock_t cpu_deadman_counter; /* used by deadman() */ 1710Sstevel@tonic-gate uint_t cpu_deadman_countdown; /* used by deadman() */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate kmutex_t cpu_cpc_ctxlock; /* protects context for idle thread */ 1740Sstevel@tonic-gate kcpc_ctx_t *cpu_cpc_ctx; /* performance counter context */ 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * Configuration information for the processor_info system call. 1780Sstevel@tonic-gate */ 1790Sstevel@tonic-gate processor_info_t cpu_type_info; /* config info */ 1800Sstevel@tonic-gate time_t cpu_state_begin; /* when CPU entered current state */ 1810Sstevel@tonic-gate char cpu_cpr_flags; /* CPR related info */ 1820Sstevel@tonic-gate struct cyc_cpu *cpu_cyclic; /* per cpu cyclic subsystem data */ 1830Sstevel@tonic-gate struct squeue_set_s *cpu_squeue_set; /* per cpu squeue set */ 1840Sstevel@tonic-gate struct nvlist *cpu_props; /* pool-related properties */ 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate krwlock_t cpu_ft_lock; /* DTrace: fasttrap lock */ 1870Sstevel@tonic-gate uintptr_t cpu_dtrace_caller; /* DTrace: caller, if any */ 1880Sstevel@tonic-gate hrtime_t cpu_dtrace_chillmark; /* DTrace: chill mark time */ 1890Sstevel@tonic-gate hrtime_t cpu_dtrace_chilled; /* DTrace: total chill time */ 1901058Sesolom volatile uint16_t cpu_mstate; /* cpu microstate */ 1911058Sesolom volatile uint16_t cpu_mstate_gen; /* generation counter */ 1921058Sesolom volatile hrtime_t cpu_mstate_start; /* cpu microstate start time */ 1931058Sesolom volatile hrtime_t cpu_acct[NCMSTATES]; /* cpu microstate data */ 194590Sesolom hrtime_t cpu_intracct[NCMSTATES]; /* interrupt mstate data */ 1950Sstevel@tonic-gate hrtime_t cpu_waitrq; /* cpu run-queue wait time */ 1960Sstevel@tonic-gate struct loadavg_s cpu_loadavg; /* loadavg info for this cpu */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate char *cpu_idstr; /* for printing and debugging */ 1990Sstevel@tonic-gate char *cpu_brandstr; /* for printing */ 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * Sum of all device interrupt weights that are currently directed at 2030Sstevel@tonic-gate * this cpu. Cleared at start of interrupt redistribution. 2040Sstevel@tonic-gate */ 2050Sstevel@tonic-gate int32_t cpu_intr_weight; 206414Skchow void *cpu_vm_data; 2070Sstevel@tonic-gate 2081892Sesaxe struct cpu_physid *cpu_physid; /* physical associations */ 2091892Sesaxe 2104718Smh27603 uint64_t cpu_curr_clock; /* current clock freq in Hz */ 2114718Smh27603 char *cpu_supp_freqs; /* supported freqs in Hz */ 2124718Smh27603 2138803SJonathan.Haslam@Sun.COM uintptr_t cpu_cpcprofile_pc; /* kernel PC in cpc interrupt */ 2148803SJonathan.Haslam@Sun.COM uintptr_t cpu_cpcprofile_upc; /* user PC in cpc interrupt */ 2158803SJonathan.Haslam@Sun.COM 2162722Sjohnlev /* 2175076Smishra * Interrupt load factor used by dispatcher & softcall 2185076Smishra */ 2195076Smishra hrtime_t cpu_intrlast; /* total interrupt time (nsec) */ 2205076Smishra int cpu_intrload; /* interrupt load factor (0-99%) */ 2215076Smishra 2228408SEric.Saxe@Sun.COM uint_t cpu_rotor; /* for cheap pseudo-random numbers */ 2238408SEric.Saxe@Sun.COM 22411389SAlexander.Kolbasov@Sun.COM struct cu_cpu_info *cpu_cu_info; /* capacity & util. info */ 22511389SAlexander.Kolbasov@Sun.COM 22611389SAlexander.Kolbasov@Sun.COM /* 22711389SAlexander.Kolbasov@Sun.COM * cpu_generation is updated whenever CPU goes on-line or off-line. 22811389SAlexander.Kolbasov@Sun.COM * Updates to cpu_generation are protected by cpu_lock. 22911389SAlexander.Kolbasov@Sun.COM * 23011389SAlexander.Kolbasov@Sun.COM * See CPU_NEW_GENERATION() macro below. 23111389SAlexander.Kolbasov@Sun.COM */ 23211389SAlexander.Kolbasov@Sun.COM volatile uint_t cpu_generation; /* tracking on/off-line */ 23311389SAlexander.Kolbasov@Sun.COM 2345076Smishra /* 2352722Sjohnlev * New members must be added /before/ this member, as the CTF tools 2362722Sjohnlev * rely on this being the last field before cpu_m, so they can 2372722Sjohnlev * correctly calculate the offset when synthetically adding the cpu_m 2382722Sjohnlev * member in objects that do not have it. This fixup is required for 2392722Sjohnlev * uniquification to work correctly. 2402722Sjohnlev */ 2412722Sjohnlev uintptr_t cpu_m_pad; 2422722Sjohnlev 2430Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) 2440Sstevel@tonic-gate struct machcpu cpu_m; /* per architecture info */ 2450Sstevel@tonic-gate #endif 2460Sstevel@tonic-gate } cpu_t; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * The cpu_core structure consists of per-CPU state available in any context. 2500Sstevel@tonic-gate * On some architectures, this may mean that the page(s) containing the 2510Sstevel@tonic-gate * NCPU-sized array of cpu_core structures must be locked in the TLB -- it 2520Sstevel@tonic-gate * is up to the platform to assure that this is performed properly. Note that 2530Sstevel@tonic-gate * the structure is sized to avoid false sharing. 2540Sstevel@tonic-gate */ 2558803SJonathan.Haslam@Sun.COM #define CPUC_SIZE (sizeof (uint16_t) + sizeof (uint8_t) + \ 2568803SJonathan.Haslam@Sun.COM sizeof (uintptr_t) + sizeof (kmutex_t)) 2570Sstevel@tonic-gate #define CPUC_PADSIZE CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate typedef struct cpu_core { 2600Sstevel@tonic-gate uint16_t cpuc_dtrace_flags; /* DTrace flags */ 2618803SJonathan.Haslam@Sun.COM uint8_t cpuc_dcpc_intr_state; /* DCPC provider intr state */ 2620Sstevel@tonic-gate uint8_t cpuc_pad[CPUC_PADSIZE]; /* padding */ 2630Sstevel@tonic-gate uintptr_t cpuc_dtrace_illval; /* DTrace illegal value */ 2640Sstevel@tonic-gate kmutex_t cpuc_pid_lock; /* DTrace pid provider lock */ 2650Sstevel@tonic-gate } cpu_core_t; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate #ifdef _KERNEL 2680Sstevel@tonic-gate extern cpu_core_t cpu_core[]; 2690Sstevel@tonic-gate #endif /* _KERNEL */ 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * CPU_ON_INTR() macro. Returns non-zero if currently on interrupt stack. 2730Sstevel@tonic-gate * Note that this isn't a test for a high PIL. For example, cpu_intr_actv 2740Sstevel@tonic-gate * does not get updated when we go through sys_trap from TL>0 at high PIL. 2750Sstevel@tonic-gate * getpil() should be used instead to check for PIL levels. 2760Sstevel@tonic-gate */ 2770Sstevel@tonic-gate #define CPU_ON_INTR(cpup) ((cpup)->cpu_intr_actv >> (LOCK_LEVEL + 1)) 2780Sstevel@tonic-gate 2798408SEric.Saxe@Sun.COM /* 2809717SColin.Yi@Sun.COM * Check to see if an interrupt thread might be active at a given ipl. 2819717SColin.Yi@Sun.COM * If so return true. 2829717SColin.Yi@Sun.COM * We must be conservative--it is ok to give a false yes, but a false no 2839717SColin.Yi@Sun.COM * will cause disaster. (But if the situation changes after we check it is 2849717SColin.Yi@Sun.COM * ok--the caller is trying to ensure that an interrupt routine has been 2859717SColin.Yi@Sun.COM * exited). 2869717SColin.Yi@Sun.COM * This is used when trying to remove an interrupt handler from an autovector 2879717SColin.Yi@Sun.COM * list in avintr.c. 2889717SColin.Yi@Sun.COM */ 2899717SColin.Yi@Sun.COM #define INTR_ACTIVE(cpup, level) \ 2909717SColin.Yi@Sun.COM ((level) <= LOCK_LEVEL ? \ 2919717SColin.Yi@Sun.COM ((cpup)->cpu_intr_actv & (1 << (level))) : (CPU_ON_INTR(cpup))) 2929717SColin.Yi@Sun.COM 2939717SColin.Yi@Sun.COM /* 2948408SEric.Saxe@Sun.COM * CPU_PSEUDO_RANDOM() returns a per CPU value that changes each time one 2958408SEric.Saxe@Sun.COM * looks at it. It's meant as a cheap mechanism to be incorporated in routines 2968408SEric.Saxe@Sun.COM * wanting to avoid biasing, but where true randomness isn't needed (just 2978408SEric.Saxe@Sun.COM * something that changes). 2988408SEric.Saxe@Sun.COM */ 2998408SEric.Saxe@Sun.COM #define CPU_PSEUDO_RANDOM() (CPU->cpu_rotor++) 3008408SEric.Saxe@Sun.COM 3010Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate #define INTR_STACK_SIZE MAX(DEFAULTSTKSZ, PAGESIZE) 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate /* MEMBERS PROTECTED BY "atomicity": cpu_flags */ 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* 3080Sstevel@tonic-gate * Flags in the CPU structure. 3090Sstevel@tonic-gate * 3100Sstevel@tonic-gate * These are protected by cpu_lock (except during creation). 3110Sstevel@tonic-gate * 3120Sstevel@tonic-gate * Offlined-CPUs have three stages of being offline: 3130Sstevel@tonic-gate * 3140Sstevel@tonic-gate * CPU_ENABLE indicates that the CPU is participating in I/O interrupts 3150Sstevel@tonic-gate * that can be directed at a number of different CPUs. If CPU_ENABLE 3160Sstevel@tonic-gate * is off, the CPU will not be given interrupts that can be sent elsewhere, 3170Sstevel@tonic-gate * but will still get interrupts from devices associated with that CPU only, 3180Sstevel@tonic-gate * and from other CPUs. 3190Sstevel@tonic-gate * 3200Sstevel@tonic-gate * CPU_OFFLINE indicates that the dispatcher should not allow any threads 3210Sstevel@tonic-gate * other than interrupt threads to run on that CPU. A CPU will not have 3220Sstevel@tonic-gate * CPU_OFFLINE set if there are any bound threads (besides interrupts). 3230Sstevel@tonic-gate * 3240Sstevel@tonic-gate * CPU_QUIESCED is set if p_offline was able to completely turn idle the 3250Sstevel@tonic-gate * CPU and it will not have to run interrupt threads. In this case it'll 3260Sstevel@tonic-gate * stay in the idle loop until CPU_QUIESCED is turned off. 3270Sstevel@tonic-gate * 3280Sstevel@tonic-gate * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully 3290Sstevel@tonic-gate * suspended (in the suspend path), or have yet to be resumed (in the resume 3300Sstevel@tonic-gate * case). 3310Sstevel@tonic-gate * 3320Sstevel@tonic-gate * On some platforms CPUs can be individually powered off. 3330Sstevel@tonic-gate * The following flags are set for powered off CPUs: CPU_QUIESCED, 3340Sstevel@tonic-gate * CPU_OFFLINE, and CPU_POWEROFF. The following flags are cleared: 3350Sstevel@tonic-gate * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE. 3360Sstevel@tonic-gate */ 3370Sstevel@tonic-gate #define CPU_RUNNING 0x001 /* CPU running */ 3380Sstevel@tonic-gate #define CPU_READY 0x002 /* CPU ready for cross-calls */ 3390Sstevel@tonic-gate #define CPU_QUIESCED 0x004 /* CPU will stay in idle */ 3400Sstevel@tonic-gate #define CPU_EXISTS 0x008 /* CPU is configured */ 3410Sstevel@tonic-gate #define CPU_ENABLE 0x010 /* CPU enabled for interrupts */ 3420Sstevel@tonic-gate #define CPU_OFFLINE 0x020 /* CPU offline via p_online */ 3430Sstevel@tonic-gate #define CPU_POWEROFF 0x040 /* CPU is powered off */ 3440Sstevel@tonic-gate #define CPU_FROZEN 0x080 /* CPU is frozen via CPR suspend */ 3450Sstevel@tonic-gate #define CPU_SPARE 0x100 /* CPU offline available for use */ 3460Sstevel@tonic-gate #define CPU_FAULTED 0x200 /* CPU offline diagnosed faulty */ 3470Sstevel@tonic-gate 3483446Smrj #define FMT_CPU_FLAGS \ 3493446Smrj "\20\12fault\11spare\10frozen" \ 3503446Smrj "\7poweroff\6offline\5enable\4exist\3quiesced\2ready\1run" 3513446Smrj 3520Sstevel@tonic-gate #define CPU_ACTIVE(cpu) (((cpu)->cpu_flags & CPU_OFFLINE) == 0) 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate /* 3550Sstevel@tonic-gate * Flags for cpu_offline(), cpu_faulted(), and cpu_spare(). 3560Sstevel@tonic-gate */ 3570Sstevel@tonic-gate #define CPU_FORCED 0x0001 /* Force CPU offline */ 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate /* 3600Sstevel@tonic-gate * DTrace flags. 3610Sstevel@tonic-gate */ 3620Sstevel@tonic-gate #define CPU_DTRACE_NOFAULT 0x0001 /* Don't fault */ 3630Sstevel@tonic-gate #define CPU_DTRACE_DROP 0x0002 /* Drop this ECB */ 3640Sstevel@tonic-gate #define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */ 3650Sstevel@tonic-gate #define CPU_DTRACE_BADALIGN 0x0008 /* DTrace fault: bad alignment */ 3660Sstevel@tonic-gate #define CPU_DTRACE_DIVZERO 0x0010 /* DTrace fault: divide by zero */ 3670Sstevel@tonic-gate #define CPU_DTRACE_ILLOP 0x0020 /* DTrace fault: illegal operation */ 3680Sstevel@tonic-gate #define CPU_DTRACE_NOSCRATCH 0x0040 /* DTrace fault: out of scratch */ 3690Sstevel@tonic-gate #define CPU_DTRACE_KPRIV 0x0080 /* DTrace fault: bad kernel access */ 3700Sstevel@tonic-gate #define CPU_DTRACE_UPRIV 0x0100 /* DTrace fault: bad user access */ 3710Sstevel@tonic-gate #define CPU_DTRACE_TUPOFLOW 0x0200 /* DTrace fault: tuple stack overflow */ 3720Sstevel@tonic-gate #if defined(__sparc) 3730Sstevel@tonic-gate #define CPU_DTRACE_FAKERESTORE 0x0400 /* pid provider hint to getreg */ 3740Sstevel@tonic-gate #endif 3750Sstevel@tonic-gate #define CPU_DTRACE_ENTRY 0x0800 /* pid provider hint to ustack() */ 3763682Sjhaslam #define CPU_DTRACE_BADSTACK 0x1000 /* DTrace fault: bad stack */ 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate #define CPU_DTRACE_FAULT (CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \ 3790Sstevel@tonic-gate CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \ 3800Sstevel@tonic-gate CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \ 3813682Sjhaslam CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \ 3823682Sjhaslam CPU_DTRACE_BADSTACK) 3830Sstevel@tonic-gate #define CPU_DTRACE_ERROR (CPU_DTRACE_FAULT | CPU_DTRACE_DROP) 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate /* 3860Sstevel@tonic-gate * Dispatcher flags 3870Sstevel@tonic-gate * These flags must be changed only by the current CPU. 3880Sstevel@tonic-gate */ 3890Sstevel@tonic-gate #define CPU_DISP_DONTSTEAL 0x01 /* CPU undergoing context swtch */ 3900Sstevel@tonic-gate #define CPU_DISP_HALTED 0x02 /* CPU halted waiting for interrupt */ 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate #endif /* _KERNEL || _KMEMUSER */ 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate #if (defined(_KERNEL) || defined(_KMEMUSER)) && defined(_MACHDEP) 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate /* 3970Sstevel@tonic-gate * Macros for manipulating sets of CPUs as a bitmap. Note that this 3980Sstevel@tonic-gate * bitmap may vary in size depending on the maximum CPU id a specific 3990Sstevel@tonic-gate * platform supports. This may be different than the number of CPUs 4000Sstevel@tonic-gate * the platform supports, since CPU ids can be sparse. We define two 4010Sstevel@tonic-gate * sets of macros; one for platforms where the maximum CPU id is less 4020Sstevel@tonic-gate * than the number of bits in a single word (32 in a 32-bit kernel, 4030Sstevel@tonic-gate * 64 in a 64-bit kernel), and one for platforms that require bitmaps 4040Sstevel@tonic-gate * of more than one word. 4050Sstevel@tonic-gate */ 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate #define CPUSET_WORDS BT_BITOUL(NCPU) 4080Sstevel@tonic-gate #define CPUSET_NOTINSET ((uint_t)-1) 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate #if CPUSET_WORDS > 1 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate typedef struct cpuset { 4130Sstevel@tonic-gate ulong_t cpub[CPUSET_WORDS]; 4140Sstevel@tonic-gate } cpuset_t; 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /* 4170Sstevel@tonic-gate * Private functions for manipulating cpusets that do not fit in a 4180Sstevel@tonic-gate * single word. These should not be used directly; instead the 4190Sstevel@tonic-gate * CPUSET_* macros should be used so the code will be portable 4200Sstevel@tonic-gate * across different definitions of NCPU. 4210Sstevel@tonic-gate */ 4220Sstevel@tonic-gate extern void cpuset_all(cpuset_t *); 4230Sstevel@tonic-gate extern void cpuset_all_but(cpuset_t *, uint_t); 4240Sstevel@tonic-gate extern int cpuset_isnull(cpuset_t *); 4250Sstevel@tonic-gate extern int cpuset_cmp(cpuset_t *, cpuset_t *); 4260Sstevel@tonic-gate extern void cpuset_only(cpuset_t *, uint_t); 4270Sstevel@tonic-gate extern uint_t cpuset_find(cpuset_t *); 4282492Sha137994 extern void cpuset_bounds(cpuset_t *, uint_t *, uint_t *); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate #define CPUSET_ALL(set) cpuset_all(&(set)) 4310Sstevel@tonic-gate #define CPUSET_ALL_BUT(set, cpu) cpuset_all_but(&(set), cpu) 4320Sstevel@tonic-gate #define CPUSET_ONLY(set, cpu) cpuset_only(&(set), cpu) 4330Sstevel@tonic-gate #define CPU_IN_SET(set, cpu) BT_TEST((set).cpub, cpu) 4340Sstevel@tonic-gate #define CPUSET_ADD(set, cpu) BT_SET((set).cpub, cpu) 4350Sstevel@tonic-gate #define CPUSET_DEL(set, cpu) BT_CLEAR((set).cpub, cpu) 4360Sstevel@tonic-gate #define CPUSET_ISNULL(set) cpuset_isnull(&(set)) 4370Sstevel@tonic-gate #define CPUSET_ISEQUAL(set1, set2) cpuset_cmp(&(set1), &(set2)) 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate /* 4400Sstevel@tonic-gate * Find one CPU in the cpuset. 4410Sstevel@tonic-gate * Sets "cpu" to the id of the found CPU, or CPUSET_NOTINSET if no cpu 4420Sstevel@tonic-gate * could be found. (i.e. empty set) 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate #define CPUSET_FIND(set, cpu) { \ 4450Sstevel@tonic-gate cpu = cpuset_find(&(set)); \ 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate /* 4492492Sha137994 * Determine the smallest and largest CPU id in the set. Returns 4502492Sha137994 * CPUSET_NOTINSET in smallest and largest when set is empty. 4512492Sha137994 */ 4522492Sha137994 #define CPUSET_BOUNDS(set, smallest, largest) { \ 4532492Sha137994 cpuset_bounds(&(set), &(smallest), &(largest)); \ 4542492Sha137994 } 4552492Sha137994 4562492Sha137994 /* 4570Sstevel@tonic-gate * Atomic cpuset operations 4580Sstevel@tonic-gate * These are safe to use for concurrent cpuset manipulations. 4590Sstevel@tonic-gate * "xdel" and "xadd" are exclusive operations, that set "result" to "0" 4600Sstevel@tonic-gate * if the add or del was successful, or "-1" if not successful. 4610Sstevel@tonic-gate * (e.g. attempting to add a cpu to a cpuset that's already there, or 4620Sstevel@tonic-gate * deleting a cpu that's not in the cpuset) 4630Sstevel@tonic-gate */ 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate #define CPUSET_ATOMIC_DEL(set, cpu) BT_ATOMIC_CLEAR((set).cpub, (cpu)) 4660Sstevel@tonic-gate #define CPUSET_ATOMIC_ADD(set, cpu) BT_ATOMIC_SET((set).cpub, (cpu)) 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate #define CPUSET_ATOMIC_XADD(set, cpu, result) \ 4690Sstevel@tonic-gate BT_ATOMIC_SET_EXCL((set).cpub, cpu, result) 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate #define CPUSET_ATOMIC_XDEL(set, cpu, result) \ 4720Sstevel@tonic-gate BT_ATOMIC_CLEAR_EXCL((set).cpub, cpu, result) 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate #define CPUSET_OR(set1, set2) { \ 4760Sstevel@tonic-gate int _i; \ 4770Sstevel@tonic-gate for (_i = 0; _i < CPUSET_WORDS; _i++) \ 4780Sstevel@tonic-gate (set1).cpub[_i] |= (set2).cpub[_i]; \ 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4815076Smishra #define CPUSET_XOR(set1, set2) { \ 4825076Smishra int _i; \ 4835076Smishra for (_i = 0; _i < CPUSET_WORDS; _i++) \ 4845076Smishra (set1).cpub[_i] ^= (set2).cpub[_i]; \ 4855076Smishra } 4865076Smishra 4870Sstevel@tonic-gate #define CPUSET_AND(set1, set2) { \ 4880Sstevel@tonic-gate int _i; \ 4890Sstevel@tonic-gate for (_i = 0; _i < CPUSET_WORDS; _i++) \ 4900Sstevel@tonic-gate (set1).cpub[_i] &= (set2).cpub[_i]; \ 4910Sstevel@tonic-gate } 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate #define CPUSET_ZERO(set) { \ 4940Sstevel@tonic-gate int _i; \ 4950Sstevel@tonic-gate for (_i = 0; _i < CPUSET_WORDS; _i++) \ 4960Sstevel@tonic-gate (set).cpub[_i] = 0; \ 4970Sstevel@tonic-gate } 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate #elif CPUSET_WORDS == 1 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate typedef ulong_t cpuset_t; /* a set of CPUs */ 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate #define CPUSET(cpu) (1UL << (cpu)) 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate #define CPUSET_ALL(set) ((void)((set) = ~0UL)) 5060Sstevel@tonic-gate #define CPUSET_ALL_BUT(set, cpu) ((void)((set) = ~CPUSET(cpu))) 5070Sstevel@tonic-gate #define CPUSET_ONLY(set, cpu) ((void)((set) = CPUSET(cpu))) 5080Sstevel@tonic-gate #define CPU_IN_SET(set, cpu) ((set) & CPUSET(cpu)) 5090Sstevel@tonic-gate #define CPUSET_ADD(set, cpu) ((void)((set) |= CPUSET(cpu))) 5100Sstevel@tonic-gate #define CPUSET_DEL(set, cpu) ((void)((set) &= ~CPUSET(cpu))) 5110Sstevel@tonic-gate #define CPUSET_ISNULL(set) ((set) == 0) 5120Sstevel@tonic-gate #define CPUSET_ISEQUAL(set1, set2) ((set1) == (set2)) 5130Sstevel@tonic-gate #define CPUSET_OR(set1, set2) ((void)((set1) |= (set2))) 5145076Smishra #define CPUSET_XOR(set1, set2) ((void)((set1) ^= (set2))) 5150Sstevel@tonic-gate #define CPUSET_AND(set1, set2) ((void)((set1) &= (set2))) 5160Sstevel@tonic-gate #define CPUSET_ZERO(set) ((void)((set) = 0)) 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate #define CPUSET_FIND(set, cpu) { \ 5190Sstevel@tonic-gate cpu = (uint_t)(lowbit(set) - 1); \ 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate 5222492Sha137994 #define CPUSET_BOUNDS(set, smallest, largest) { \ 5232492Sha137994 smallest = (uint_t)(lowbit(set) - 1); \ 5242492Sha137994 largest = (uint_t)(highbit(set) - 1); \ 5252492Sha137994 } 5262492Sha137994 5270Sstevel@tonic-gate #define CPUSET_ATOMIC_DEL(set, cpu) atomic_and_long(&(set), ~CPUSET(cpu)) 5280Sstevel@tonic-gate #define CPUSET_ATOMIC_ADD(set, cpu) atomic_or_long(&(set), CPUSET(cpu)) 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate #define CPUSET_ATOMIC_XADD(set, cpu, result) \ 5310Sstevel@tonic-gate { result = atomic_set_long_excl(&(set), (cpu)); } 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate #define CPUSET_ATOMIC_XDEL(set, cpu, result) \ 5340Sstevel@tonic-gate { result = atomic_clear_long_excl(&(set), (cpu)); } 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate #else /* CPUSET_WORDS <= 0 */ 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate #error NCPU is undefined or invalid 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate #endif /* CPUSET_WORDS */ 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate extern cpuset_t cpu_seqid_inuse; 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate #endif /* (_KERNEL || _KMEMUSER) && _MACHDEP */ 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate #define CPU_CPR_OFFLINE 0x0 5470Sstevel@tonic-gate #define CPU_CPR_ONLINE 0x1 5480Sstevel@tonic-gate #define CPU_CPR_IS_OFFLINE(cpu) (((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE) == 0) 5495295Srandyf #define CPU_CPR_IS_ONLINE(cpu) ((cpu)->cpu_cpr_flags & CPU_CPR_ONLINE) 5500Sstevel@tonic-gate #define CPU_SET_CPR_FLAGS(cpu, flag) ((cpu)->cpu_cpr_flags |= flag) 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate extern struct cpu *cpu[]; /* indexed by CPU number */ 5558408SEric.Saxe@Sun.COM extern struct cpu **cpu_seq; /* indexed by sequential CPU id */ 5560Sstevel@tonic-gate extern cpu_t *cpu_list; /* list of CPUs */ 5575788Smv143129 extern cpu_t *cpu_active; /* list of active CPUs */ 5580Sstevel@tonic-gate extern int ncpus; /* number of CPUs present */ 5590Sstevel@tonic-gate extern int ncpus_online; /* number of CPUs not quiesced */ 5600Sstevel@tonic-gate extern int max_ncpus; /* max present before ncpus is known */ 5610Sstevel@tonic-gate extern int boot_max_ncpus; /* like max_ncpus but for real */ 5626880Sdv142724 extern int boot_ncpus; /* # cpus present @ boot */ 5630Sstevel@tonic-gate extern processorid_t max_cpuid; /* maximum CPU number */ 5640Sstevel@tonic-gate extern struct cpu *cpu_inmotion; /* offline or partition move target */ 5653792Sakolb extern cpu_t *clock_cpu_list; 566*12908SPavel.Tatashin@Sun.COM extern processorid_t max_cpu_seqid_ever; /* maximum seqid ever given */ 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate #if defined(__i386) || defined(__amd64) 5690Sstevel@tonic-gate extern struct cpu *curcpup(void); 5700Sstevel@tonic-gate #define CPU (curcpup()) /* Pointer to current CPU */ 5710Sstevel@tonic-gate #else 5720Sstevel@tonic-gate #define CPU (curthread->t_cpu) /* Pointer to current CPU */ 5730Sstevel@tonic-gate #endif 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate /* 5760Sstevel@tonic-gate * CPU_CURRENT indicates to thread_affinity_set to use CPU->cpu_id 5770Sstevel@tonic-gate * as the target and to grab cpu_lock instead of requiring the caller 5780Sstevel@tonic-gate * to grab it. 5790Sstevel@tonic-gate */ 5800Sstevel@tonic-gate #define CPU_CURRENT -3 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* 5830Sstevel@tonic-gate * Per-CPU statistics 5840Sstevel@tonic-gate * 5850Sstevel@tonic-gate * cpu_stats_t contains numerous system and VM-related statistics, in the form 5860Sstevel@tonic-gate * of gauges or monotonically-increasing event occurrence counts. 5870Sstevel@tonic-gate */ 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate #define CPU_STATS_ENTER_K() kpreempt_disable() 5900Sstevel@tonic-gate #define CPU_STATS_EXIT_K() kpreempt_enable() 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate #define CPU_STATS_ADD_K(class, stat, amount) \ 5930Sstevel@tonic-gate { kpreempt_disable(); /* keep from switching CPUs */\ 5940Sstevel@tonic-gate CPU_STATS_ADDQ(CPU, class, stat, amount); \ 5950Sstevel@tonic-gate kpreempt_enable(); \ 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate #define CPU_STATS_ADDQ(cp, class, stat, amount) { \ 5990Sstevel@tonic-gate extern void __dtrace_probe___cpu_##class##info_##stat(uint_t, \ 6000Sstevel@tonic-gate uint64_t *, cpu_t *); \ 6010Sstevel@tonic-gate uint64_t *stataddr = &((cp)->cpu_stats.class.stat); \ 6020Sstevel@tonic-gate __dtrace_probe___cpu_##class##info_##stat((amount), \ 6030Sstevel@tonic-gate stataddr, cp); \ 6040Sstevel@tonic-gate *(stataddr) += (amount); \ 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate #define CPU_STATS(cp, stat) \ 6080Sstevel@tonic-gate ((cp)->cpu_stats.stat) 6090Sstevel@tonic-gate 61011389SAlexander.Kolbasov@Sun.COM /* 61111389SAlexander.Kolbasov@Sun.COM * Increment CPU generation value. 61211389SAlexander.Kolbasov@Sun.COM * This macro should be called whenever CPU goes on-line or off-line. 61311389SAlexander.Kolbasov@Sun.COM * Updates to cpu_generation should be protected by cpu_lock. 61411389SAlexander.Kolbasov@Sun.COM */ 61511389SAlexander.Kolbasov@Sun.COM #define CPU_NEW_GENERATION(cp) ((cp)->cpu_generation++) 61611389SAlexander.Kolbasov@Sun.COM 6170Sstevel@tonic-gate #endif /* _KERNEL || _KMEMUSER */ 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate /* 6200Sstevel@tonic-gate * CPU support routines. 6210Sstevel@tonic-gate */ 6220Sstevel@tonic-gate #if defined(_KERNEL) && defined(__STDC__) /* not for genassym.c */ 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate struct zone; 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate void cpu_list_init(cpu_t *); 6270Sstevel@tonic-gate void cpu_add_unit(cpu_t *); 6280Sstevel@tonic-gate void cpu_del_unit(int cpuid); 6290Sstevel@tonic-gate void cpu_add_active(cpu_t *); 6300Sstevel@tonic-gate void cpu_kstat_init(cpu_t *); 6310Sstevel@tonic-gate void cpu_visibility_add(cpu_t *, struct zone *); 6320Sstevel@tonic-gate void cpu_visibility_remove(cpu_t *, struct zone *); 6330Sstevel@tonic-gate void cpu_visibility_configure(cpu_t *, struct zone *); 6340Sstevel@tonic-gate void cpu_visibility_unconfigure(cpu_t *, struct zone *); 6350Sstevel@tonic-gate void cpu_visibility_online(cpu_t *, struct zone *); 6360Sstevel@tonic-gate void cpu_visibility_offline(cpu_t *, struct zone *); 6370Sstevel@tonic-gate void cpu_create_intrstat(cpu_t *); 6380Sstevel@tonic-gate void cpu_delete_intrstat(cpu_t *); 6390Sstevel@tonic-gate int cpu_kstat_intrstat_update(kstat_t *, int); 6400Sstevel@tonic-gate void cpu_intr_swtch_enter(kthread_t *); 6410Sstevel@tonic-gate void cpu_intr_swtch_exit(kthread_t *); 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate void mbox_lock_init(void); /* initialize cross-call locks */ 6440Sstevel@tonic-gate void mbox_init(int cpun); /* initialize cross-calls */ 6450Sstevel@tonic-gate void poke_cpu(int cpun); /* interrupt another CPU (to preempt) */ 6460Sstevel@tonic-gate 6473446Smrj /* 6483446Smrj * values for safe_list. Pause state that CPUs are in. 6493446Smrj */ 6503446Smrj #define PAUSE_IDLE 0 /* normal state */ 6513446Smrj #define PAUSE_READY 1 /* paused thread ready to spl */ 6523446Smrj #define PAUSE_WAIT 2 /* paused thread is spl-ed high */ 6533446Smrj #define PAUSE_DIE 3 /* tell pause thread to leave */ 6543446Smrj #define PAUSE_DEAD 4 /* pause thread has left */ 6553446Smrj 6563446Smrj void mach_cpu_pause(volatile char *); 6573446Smrj 6580Sstevel@tonic-gate void pause_cpus(cpu_t *off_cp); 6590Sstevel@tonic-gate void start_cpus(void); 6600Sstevel@tonic-gate int cpus_paused(void); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate void cpu_pause_init(void); 6630Sstevel@tonic-gate cpu_t *cpu_get(processorid_t cpun); /* get the CPU struct associated */ 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate int cpu_online(cpu_t *cp); /* take cpu online */ 6660Sstevel@tonic-gate int cpu_offline(cpu_t *cp, int flags); /* take cpu offline */ 6670Sstevel@tonic-gate int cpu_spare(cpu_t *cp, int flags); /* take cpu to spare */ 6680Sstevel@tonic-gate int cpu_faulted(cpu_t *cp, int flags); /* take cpu to faulted */ 6690Sstevel@tonic-gate int cpu_poweron(cpu_t *cp); /* take powered-off cpu to offline */ 6700Sstevel@tonic-gate int cpu_poweroff(cpu_t *cp); /* take offline cpu to powered-off */ 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate cpu_t *cpu_intr_next(cpu_t *cp); /* get next online CPU taking intrs */ 6730Sstevel@tonic-gate int cpu_intr_count(cpu_t *cp); /* count # of CPUs handling intrs */ 6740Sstevel@tonic-gate int cpu_intr_on(cpu_t *cp); /* CPU taking I/O interrupts? */ 6750Sstevel@tonic-gate void cpu_intr_enable(cpu_t *cp); /* enable I/O interrupts */ 6760Sstevel@tonic-gate int cpu_intr_disable(cpu_t *cp); /* disable I/O interrupts */ 6771455Sandrei void cpu_intr_alloc(cpu_t *cp, int n); /* allocate interrupt threads */ 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * Routines for checking CPU states. 6810Sstevel@tonic-gate */ 6820Sstevel@tonic-gate int cpu_is_online(cpu_t *); /* check if CPU is online */ 6830Sstevel@tonic-gate int cpu_is_nointr(cpu_t *); /* check if CPU can service intrs */ 6840Sstevel@tonic-gate int cpu_is_active(cpu_t *); /* check if CPU can run threads */ 6850Sstevel@tonic-gate int cpu_is_offline(cpu_t *); /* check if CPU is offline */ 6860Sstevel@tonic-gate int cpu_is_poweredoff(cpu_t *); /* check if CPU is powered off */ 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate int cpu_flagged_online(cpu_flag_t); /* flags show CPU is online */ 6890Sstevel@tonic-gate int cpu_flagged_nointr(cpu_flag_t); /* flags show CPU not handling intrs */ 6900Sstevel@tonic-gate int cpu_flagged_active(cpu_flag_t); /* flags show CPU scheduling threads */ 6910Sstevel@tonic-gate int cpu_flagged_offline(cpu_flag_t); /* flags show CPU is offline */ 6920Sstevel@tonic-gate int cpu_flagged_poweredoff(cpu_flag_t); /* flags show CPU is powered off */ 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate /* 6950Sstevel@tonic-gate * The processor_info(2) state of a CPU is a simplified representation suitable 6960Sstevel@tonic-gate * for use by an application program. Kernel subsystems should utilize the 6970Sstevel@tonic-gate * internal per-CPU state as given by the cpu_flags member of the cpu structure, 6980Sstevel@tonic-gate * as this information may include platform- or architecture-specific state 6990Sstevel@tonic-gate * critical to a subsystem's disposition of a particular CPU. 7000Sstevel@tonic-gate */ 7010Sstevel@tonic-gate void cpu_set_state(cpu_t *); /* record/timestamp current state */ 7020Sstevel@tonic-gate int cpu_get_state(cpu_t *); /* get current cpu state */ 7030Sstevel@tonic-gate const char *cpu_get_state_str(cpu_t *); /* get current cpu state as string */ 7040Sstevel@tonic-gate 7054877Smh27603 7068906SEric.Saxe@Sun.COM void cpu_set_curr_clock(uint64_t); /* indicate the current CPU's freq */ 7074877Smh27603 void cpu_set_supp_freqs(cpu_t *, const char *); /* set the CPU supported */ 7084877Smh27603 /* frequencies */ 7094877Smh27603 7100Sstevel@tonic-gate int cpu_configure(int); 7110Sstevel@tonic-gate int cpu_unconfigure(int); 7120Sstevel@tonic-gate void cpu_destroy_bound_threads(cpu_t *cp); 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate extern int cpu_bind_thread(kthread_t *tp, processorid_t bind, 7150Sstevel@tonic-gate processorid_t *obind, int *error); 7166298Sakolb extern int cpu_unbind(processorid_t cpu_id, boolean_t force); 7170Sstevel@tonic-gate extern void thread_affinity_set(kthread_t *t, int cpu_id); 7180Sstevel@tonic-gate extern void thread_affinity_clear(kthread_t *t); 7190Sstevel@tonic-gate extern void affinity_set(int cpu_id); 7200Sstevel@tonic-gate extern void affinity_clear(void); 7210Sstevel@tonic-gate extern void init_cpu_mstate(struct cpu *, int); 7220Sstevel@tonic-gate extern void term_cpu_mstate(struct cpu *); 723590Sesolom extern void new_cpu_mstate(int, hrtime_t); 724590Sesolom extern void get_cpu_mstate(struct cpu *, hrtime_t *); 7250Sstevel@tonic-gate extern void thread_nomigrate(void); 7260Sstevel@tonic-gate extern void thread_allowmigrate(void); 7270Sstevel@tonic-gate extern void weakbinding_stop(void); 7280Sstevel@tonic-gate extern void weakbinding_start(void); 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate /* 7310Sstevel@tonic-gate * The following routines affect the CPUs participation in interrupt processing, 7320Sstevel@tonic-gate * if that is applicable on the architecture. This only affects interrupts 7330Sstevel@tonic-gate * which aren't directed at the processor (not cross calls). 7340Sstevel@tonic-gate * 7350Sstevel@tonic-gate * cpu_disable_intr returns non-zero if interrupts were previously enabled. 7360Sstevel@tonic-gate */ 7370Sstevel@tonic-gate int cpu_disable_intr(struct cpu *cp); /* stop issuing interrupts to cpu */ 7380Sstevel@tonic-gate void cpu_enable_intr(struct cpu *cp); /* start issuing interrupts to cpu */ 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* 7410Sstevel@tonic-gate * The mutex cpu_lock protects cpu_flags for all CPUs, as well as the ncpus 7420Sstevel@tonic-gate * and ncpus_online counts. 7430Sstevel@tonic-gate */ 7440Sstevel@tonic-gate extern kmutex_t cpu_lock; /* lock protecting CPU data */ 7450Sstevel@tonic-gate 74611389SAlexander.Kolbasov@Sun.COM /* 74711389SAlexander.Kolbasov@Sun.COM * CPU state change events 74811389SAlexander.Kolbasov@Sun.COM * 74911389SAlexander.Kolbasov@Sun.COM * Various subsystems need to know when CPUs change their state. They get this 75011389SAlexander.Kolbasov@Sun.COM * information by registering CPU state change callbacks using 75111389SAlexander.Kolbasov@Sun.COM * register_cpu_setup_func(). Whenever any CPU changes its state, the callback 75211389SAlexander.Kolbasov@Sun.COM * function is called. The callback function is passed three arguments: 75311389SAlexander.Kolbasov@Sun.COM * 75411389SAlexander.Kolbasov@Sun.COM * Event, described by cpu_setup_t 75511389SAlexander.Kolbasov@Sun.COM * CPU ID 75611389SAlexander.Kolbasov@Sun.COM * Transparent pointer passed when registering the callback 75711389SAlexander.Kolbasov@Sun.COM * 75811389SAlexander.Kolbasov@Sun.COM * The callback function is called with cpu_lock held. The return value from the 75911389SAlexander.Kolbasov@Sun.COM * callback function is usually ignored, except for CPU_CONFIG and CPU_UNCONFIG 76011389SAlexander.Kolbasov@Sun.COM * events. For these two events, non-zero return value indicates a failure and 76111389SAlexander.Kolbasov@Sun.COM * prevents successful completion of the operation. 76211389SAlexander.Kolbasov@Sun.COM * 76311389SAlexander.Kolbasov@Sun.COM * New events may be added in the future. Callback functions should ignore any 76411389SAlexander.Kolbasov@Sun.COM * events that they do not understand. 76511389SAlexander.Kolbasov@Sun.COM * 76611389SAlexander.Kolbasov@Sun.COM * The following events provide notification callbacks: 76711389SAlexander.Kolbasov@Sun.COM * 76811389SAlexander.Kolbasov@Sun.COM * CPU_INIT A new CPU is started and added to the list of active CPUs 76911389SAlexander.Kolbasov@Sun.COM * This event is only used during boot 77011389SAlexander.Kolbasov@Sun.COM * 77111389SAlexander.Kolbasov@Sun.COM * CPU_CONFIG A newly inserted CPU is prepared for starting running code 77211389SAlexander.Kolbasov@Sun.COM * This event is called by DR code 77311389SAlexander.Kolbasov@Sun.COM * 77411389SAlexander.Kolbasov@Sun.COM * CPU_UNCONFIG CPU has been powered off and needs cleanup 77511389SAlexander.Kolbasov@Sun.COM * This event is called by DR code 77611389SAlexander.Kolbasov@Sun.COM * 77711389SAlexander.Kolbasov@Sun.COM * CPU_ON CPU is enabled but does not run anything yet 77811389SAlexander.Kolbasov@Sun.COM * 77911389SAlexander.Kolbasov@Sun.COM * CPU_INTR_ON CPU is enabled and has interrupts enabled 78011389SAlexander.Kolbasov@Sun.COM * 78111389SAlexander.Kolbasov@Sun.COM * CPU_OFF CPU is going offline but can still run threads 78211389SAlexander.Kolbasov@Sun.COM * 78311389SAlexander.Kolbasov@Sun.COM * CPU_CPUPART_OUT CPU is going to move out of its partition 78411389SAlexander.Kolbasov@Sun.COM * 78511389SAlexander.Kolbasov@Sun.COM * CPU_CPUPART_IN CPU is going to move to a new partition 78611389SAlexander.Kolbasov@Sun.COM * 78711389SAlexander.Kolbasov@Sun.COM * CPU_SETUP CPU is set up during boot and can run threads 78811389SAlexander.Kolbasov@Sun.COM */ 7890Sstevel@tonic-gate typedef enum { 7900Sstevel@tonic-gate CPU_INIT, 7910Sstevel@tonic-gate CPU_CONFIG, 7920Sstevel@tonic-gate CPU_UNCONFIG, 7930Sstevel@tonic-gate CPU_ON, 7940Sstevel@tonic-gate CPU_OFF, 7950Sstevel@tonic-gate CPU_CPUPART_IN, 7968803SJonathan.Haslam@Sun.COM CPU_CPUPART_OUT, 79711389SAlexander.Kolbasov@Sun.COM CPU_SETUP, 79811389SAlexander.Kolbasov@Sun.COM CPU_INTR_ON 7990Sstevel@tonic-gate } cpu_setup_t; 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate typedef int cpu_setup_func_t(cpu_setup_t, int, void *); 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate /* 8040Sstevel@tonic-gate * Routines used to register interest in cpu's being added to or removed 8050Sstevel@tonic-gate * from the system. 8060Sstevel@tonic-gate */ 8070Sstevel@tonic-gate extern void register_cpu_setup_func(cpu_setup_func_t *, void *); 8080Sstevel@tonic-gate extern void unregister_cpu_setup_func(cpu_setup_func_t *, void *); 8090Sstevel@tonic-gate extern void cpu_state_change_notify(int, cpu_setup_t); 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate /* 81211389SAlexander.Kolbasov@Sun.COM * Call specified function on the given CPU 81311389SAlexander.Kolbasov@Sun.COM */ 81411389SAlexander.Kolbasov@Sun.COM typedef void (*cpu_call_func_t)(uintptr_t, uintptr_t); 81511389SAlexander.Kolbasov@Sun.COM extern void cpu_call(cpu_t *, cpu_call_func_t, uintptr_t, uintptr_t); 81611389SAlexander.Kolbasov@Sun.COM 81711389SAlexander.Kolbasov@Sun.COM 81811389SAlexander.Kolbasov@Sun.COM /* 8190Sstevel@tonic-gate * Create various strings that describe the given CPU for the 8200Sstevel@tonic-gate * processor_info system call and configuration-related kstats. 8210Sstevel@tonic-gate */ 8220Sstevel@tonic-gate #define CPU_IDSTRLEN 100 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate extern void init_cpu_info(struct cpu *); 8257718SJason.Beloro@Sun.COM extern void populate_idstr(struct cpu *); 826414Skchow extern void cpu_vm_data_init(struct cpu *); 827414Skchow extern void cpu_vm_data_destroy(struct cpu *); 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate #endif /* _KERNEL */ 8300Sstevel@tonic-gate 8310Sstevel@tonic-gate #ifdef __cplusplus 8320Sstevel@tonic-gate } 8330Sstevel@tonic-gate #endif 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate #endif /* _SYS_CPUVAR_H */ 836