From abf847a083888bbed4260ecacf849ea19f23e810 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Tue, 31 Jan 2017 17:47:16 -0500 Subject: Start of an experiment to remove the use of gs for cpu local variables. --- lapic.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lapic.c') diff --git a/lapic.c b/lapic.c index 7507f97..9039665 100644 --- a/lapic.c +++ b/lapic.c @@ -99,11 +99,11 @@ lapicinit(void) } int -cpunum(void) +lapiccpunum(void) { int apicid, i; - // Cannot call cpu when interrupts are enabled: + // Cannot call cpunum when interrupts are enabled: // result not guaranteed to last long enough to be used! // Would prefer to panic but even printing is chancy here: // almost everything, including cprintf and panic, calls cpu, @@ -111,7 +111,7 @@ cpunum(void) if(readeflags()&FL_IF){ static int n; if(n++ == 0) - cprintf("cpu called from %x with interrupts enabled\n", + cprintf("cpunum called from %x with interrupts enabled\n", __builtin_return_address(0)); } -- cgit v1.2.3 From ed396c068b881877330f7d40bfce02db9b1199b3 Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 1 Feb 2017 18:04:13 -0500 Subject: Eliminate code for gs trick to track per-cpu state. We rely on lapiccpunum() to find a per-cpu id with which we locate a cpu's cpu struct. --- lapic.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'lapic.c') diff --git a/lapic.c b/lapic.c index 9039665..9a12f17 100644 --- a/lapic.c +++ b/lapic.c @@ -98,22 +98,12 @@ lapicinit(void) lapicw(TPR, 0); } +// Should be called with interrupts disabled: the calling thread shouldn't be +// rescheduled between reading lapic[ID] and checking against cpu array. int lapiccpunum(void) { int apicid, i; - - // Cannot call cpunum when interrupts are enabled: - // result not guaranteed to last long enough to be used! - // Would prefer to panic but even printing is chancy here: - // almost everything, including cprintf and panic, calls cpu, - // often indirectly through acquire and release. - if(readeflags()&FL_IF){ - static int n; - if(n++ == 0) - cprintf("cpunum called from %x with interrupts enabled\n", - __builtin_return_address(0)); - } if (!lapic) return 0; -- cgit v1.2.3 From c9fa90f7e514f27fa1ac071cd9795f3830ab6a1b Mon Sep 17 00:00:00 2001 From: Frans Kaashoek Date: Wed, 1 Feb 2017 20:36:41 -0500 Subject: A tiny bit of clean up (e.g., move code searching cpu array from lapic.c into mycpu() in proc.c. --- lapic.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'lapic.c') diff --git a/lapic.c b/lapic.c index 9a12f17..dc69eb6 100644 --- a/lapic.c +++ b/lapic.c @@ -9,7 +9,6 @@ #include "traps.h" #include "mmu.h" #include "x86.h" -#include "proc.h" // ncpu // Local APIC registers, divided by 4 for use as uint[] indices. #define ID (0x0020/4) // ID @@ -98,22 +97,12 @@ lapicinit(void) lapicw(TPR, 0); } -// Should be called with interrupts disabled: the calling thread shouldn't be -// rescheduled between reading lapic[ID] and checking against cpu array. int -lapiccpunum(void) +lapicid(void) { - int apicid, i; - if (!lapic) return 0; - - apicid = lapic[ID] >> 24; - for (i = 0; i < ncpu; ++i) { - if (cpus[i].apicid == apicid) - return i; - } - panic("unknown apicid\n"); + return lapic[ID] >> 24; } // Acknowledge interrupt. -- cgit v1.2.3