subr_smp.c (5931a9c24e798d31c4389671b8c8431911b18c5d) subr_smp.c (2f1e70693d5139b207a083e6a7255871ef15cdeb)
1/*
2 * Copyright (c) 1996, by Steve Passe
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 8 unchanged lines hidden (view full) ---

17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
1/*
2 * Copyright (c) 1996, by Steve Passe
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 8 unchanged lines hidden (view full) ---

17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 * $Id: mp_machdep.c,v 1.74 1998/05/11 01:06:06 dyson Exp $
25 * $Id: mp_machdep.c,v 1.75 1998/05/17 18:53:17 tegge Exp $
26 */
27
28#include "opt_smp.h"
29#include "opt_vm86.h"
30#include "opt_cpu.h"
31
32#ifdef SMP
33#include <machine/smptests.h>

--- 273 unchanged lines hidden (view full) ---

307pd_entry_t *IdlePTDS[NCPU];
308
309/* "my" private page table page, for BSP init */
310extern pt_entry_t SMP_prvpt[];
311
312/* Private page pointer to curcpu's PTD, used during BSP init */
313extern pd_entry_t *my_idlePTD;
314
26 */
27
28#include "opt_smp.h"
29#include "opt_vm86.h"
30#include "opt_cpu.h"
31
32#ifdef SMP
33#include <machine/smptests.h>

--- 273 unchanged lines hidden (view full) ---

307pd_entry_t *IdlePTDS[NCPU];
308
309/* "my" private page table page, for BSP init */
310extern pt_entry_t SMP_prvpt[];
311
312/* Private page pointer to curcpu's PTD, used during BSP init */
313extern pd_entry_t *my_idlePTD;
314
315struct pcb stoppcbs[NCPU];
316
315static int smp_started; /* has the system started? */
316
317/*
318 * Local data and functions.
319 */
320
321static int mp_capable;
322static u_int boot_address;

--- 1681 unchanged lines hidden (view full) ---

2004 * from executing at same time.
2005 */
2006int
2007stop_cpus(u_int map)
2008{
2009 if (!smp_started)
2010 return 0;
2011
317static int smp_started; /* has the system started? */
318
319/*
320 * Local data and functions.
321 */
322
323static int mp_capable;
324static u_int boot_address;

--- 1681 unchanged lines hidden (view full) ---

2006 * from executing at same time.
2007 */
2008int
2009stop_cpus(u_int map)
2010{
2011 if (!smp_started)
2012 return 0;
2013
2012 /* send IPI to all CPUs in map */
2013 stopped_cpus = 0;
2014
2015 /* send the Xcpustop IPI to all CPUs in map */
2016 selected_apic_ipi(map, XCPUSTOP_OFFSET, APIC_DELMODE_FIXED);
2014 /* send the Xcpustop IPI to all CPUs in map */
2015 selected_apic_ipi(map, XCPUSTOP_OFFSET, APIC_DELMODE_FIXED);
2017
2018 while (stopped_cpus != map)
2016
2017 while ((stopped_cpus & map) != map)
2019 /* spin */ ;
2020
2021 return 1;
2022}
2023
2024
2025/*
2026 * Called by a CPU to restart stopped CPUs.

--- 11 unchanged lines hidden (view full) ---

2038int
2039restart_cpus(u_int map)
2040{
2041 if (!smp_started)
2042 return 0;
2043
2044 started_cpus = map; /* signal other cpus to restart */
2045
2018 /* spin */ ;
2019
2020 return 1;
2021}
2022
2023
2024/*
2025 * Called by a CPU to restart stopped CPUs.

--- 11 unchanged lines hidden (view full) ---

2037int
2038restart_cpus(u_int map)
2039{
2040 if (!smp_started)
2041 return 0;
2042
2043 started_cpus = map; /* signal other cpus to restart */
2044
2046 while (started_cpus) /* wait for each to clear its bit */
2045 while ((stopped_cpus & map) != 0) /* wait for each to clear its bit */
2047 /* spin */ ;
2046 /* spin */ ;
2048 stopped_cpus = 0;
2049
2050 return 1;
2051}
2052
2053int smp_active = 0; /* are the APs allowed to run? */
2054SYSCTL_INT(_machdep, OID_AUTO, smp_active, CTLFLAG_RW, &smp_active, 0, "");
2055
2056/* XXX maybe should be hw.ncpu */

--- 13 unchanged lines hidden (view full) ---

2070SYSCTL_INT(_machdep, OID_AUTO, forward_irq_enabled, CTLFLAG_RW,
2071 &forward_irq_enabled, 0, "");
2072
2073/* Enable forwarding of a signal to a process running on a different CPU */
2074int forward_signal_enabled = 1;
2075SYSCTL_INT(_machdep, OID_AUTO, forward_signal_enabled, CTLFLAG_RW,
2076 &forward_signal_enabled, 0, "");
2077
2047
2048 return 1;
2049}
2050
2051int smp_active = 0; /* are the APs allowed to run? */
2052SYSCTL_INT(_machdep, OID_AUTO, smp_active, CTLFLAG_RW, &smp_active, 0, "");
2053
2054/* XXX maybe should be hw.ncpu */

--- 13 unchanged lines hidden (view full) ---

2068SYSCTL_INT(_machdep, OID_AUTO, forward_irq_enabled, CTLFLAG_RW,
2069 &forward_irq_enabled, 0, "");
2070
2071/* Enable forwarding of a signal to a process running on a different CPU */
2072int forward_signal_enabled = 1;
2073SYSCTL_INT(_machdep, OID_AUTO, forward_signal_enabled, CTLFLAG_RW,
2074 &forward_signal_enabled, 0, "");
2075
2076/* Enable forwarding of roundrobin to all other cpus */
2077int forward_roundrobin_enabled = 1;
2078SYSCTL_INT(_machdep, OID_AUTO, forward_roundrobin_enabled, CTLFLAG_RW,
2079 &forward_roundrobin_enabled, 0, "");
2080
2078/*
2079 * This is called once the rest of the system is up and running and we're
2080 * ready to let the AP's out of the pen.
2081 */
2082void ap_init(void);
2083
2084void
2085ap_init()

--- 205 unchanged lines hidden (view full) ---

2291 if (map != 0)
2292 selected_apic_ipi(map,
2293 XCPUCHECKSTATE_OFFSET, APIC_DELMODE_FIXED);
2294
2295 i = 0;
2296 while (checkstate_probed_cpus != map) {
2297 /* spin */
2298 i++;
2081/*
2082 * This is called once the rest of the system is up and running and we're
2083 * ready to let the AP's out of the pen.
2084 */
2085void ap_init(void);
2086
2087void
2088ap_init()

--- 205 unchanged lines hidden (view full) ---

2294 if (map != 0)
2295 selected_apic_ipi(map,
2296 XCPUCHECKSTATE_OFFSET, APIC_DELMODE_FIXED);
2297
2298 i = 0;
2299 while (checkstate_probed_cpus != map) {
2300 /* spin */
2301 i++;
2299 if (i == 1000000) {
2302 if (i == 100000) {
2303#ifdef BETTER_CLOCK_DIAGNOSTIC
2300 printf("forward_statclock: checkstate %x\n",
2301 checkstate_probed_cpus);
2304 printf("forward_statclock: checkstate %x\n",
2305 checkstate_probed_cpus);
2306#endif
2302 break;
2303 }
2304 }
2305
2306 /*
2307 * Step 2: walk through other processors processes, update ticks and
2308 * profiling info.
2309 */

--- 54 unchanged lines hidden (view full) ---

2364 if (map != 0)
2365 selected_apic_ipi(map,
2366 XCPUCHECKSTATE_OFFSET, APIC_DELMODE_FIXED);
2367
2368 i = 0;
2369 while (checkstate_probed_cpus != map) {
2370 /* spin */
2371 i++;
2307 break;
2308 }
2309 }
2310
2311 /*
2312 * Step 2: walk through other processors processes, update ticks and
2313 * profiling info.
2314 */

--- 54 unchanged lines hidden (view full) ---

2369 if (map != 0)
2370 selected_apic_ipi(map,
2371 XCPUCHECKSTATE_OFFSET, APIC_DELMODE_FIXED);
2372
2373 i = 0;
2374 while (checkstate_probed_cpus != map) {
2375 /* spin */
2376 i++;
2372 if (i == 1000000) {
2377 if (i == 100000) {
2378#ifdef BETTER_CLOCK_DIAGNOSTIC
2373 printf("forward_hardclock: checkstate %x\n",
2374 checkstate_probed_cpus);
2379 printf("forward_hardclock: checkstate %x\n",
2380 checkstate_probed_cpus);
2381#endif
2375 break;
2376 }
2377 }
2378
2379 /*
2380 * Step 2: walk through other processors processes, update virtual
2381 * timer and profiling timer. If stathz == 0, also update ticks and
2382 * profiling info.

--- 87 unchanged lines hidden (view full) ---

2470 break;
2471 }
2472 }
2473 if (id == (u_char) p->p_oncpu)
2474 return;
2475 }
2476}
2477
2382 break;
2383 }
2384 }
2385
2386 /*
2387 * Step 2: walk through other processors processes, update virtual
2388 * timer and profiling timer. If stathz == 0, also update ticks and
2389 * profiling info.

--- 87 unchanged lines hidden (view full) ---

2477 break;
2478 }
2479 }
2480 if (id == (u_char) p->p_oncpu)
2481 return;
2482 }
2483}
2484
2485void
2486forward_roundrobin(void)
2487{
2488 u_int map;
2489 int i;
2478
2490
2491 if (!smp_started || !invltlb_ok || cold || panicstr)
2492 return;
2493 if (!forward_roundrobin_enabled)
2494 return;
2495 resched_cpus |= other_cpus;
2496 map = other_cpus & ~stopped_cpus ;
2497#if 1
2498 selected_apic_ipi(map, XCPUAST_OFFSET, APIC_DELMODE_FIXED);
2499#else
2500 (void) all_but_self_ipi(XCPUAST_OFFSET);
2501#endif
2502 i = 0;
2503 while ((checkstate_need_ast & map) != 0) {
2504 /* spin */
2505 i++;
2506 if (i > 100000) {
2507#if 0
2508 printf("forward_roundrobin: dropped ast 0x%x\n",
2509 checkstate_need_ast & map);
2510#endif
2511 break;
2512 }
2513 }
2514}
2515
2516
2479#ifdef APIC_INTR_REORDER
2480/*
2481 * Maintain mapping from softintr vector to isr bit in local apic.
2482 */
2483void
2484set_lapic_isrloc(int intr, int vector)
2485{
2486 if (intr < 0 || intr > 32)
2487 panic("set_apic_isrloc: bad intr argument: %d",intr);
2488 if (vector < ICU_OFFSET || vector > 255)
2489 panic("set_apic_isrloc: bad vector argument: %d",vector);
2490 apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
2491 apic_isrbit_location[intr].bit = (1<<(vector & 31));
2492}
2493#endif
2517#ifdef APIC_INTR_REORDER
2518/*
2519 * Maintain mapping from softintr vector to isr bit in local apic.
2520 */
2521void
2522set_lapic_isrloc(int intr, int vector)
2523{
2524 if (intr < 0 || intr > 32)
2525 panic("set_apic_isrloc: bad intr argument: %d",intr);
2526 if (vector < ICU_OFFSET || vector > 255)
2527 panic("set_apic_isrloc: bad vector argument: %d",vector);
2528 apic_isrbit_location[intr].location = &lapic.isr0 + ((vector>>5)<<2);
2529 apic_isrbit_location[intr].bit = (1<<(vector & 31));
2530}
2531#endif