ChangeSet 1.1456, 2005/05/08 09:39:54+01:00, kmacy@xxxxxxxxxx
[PATCH] [PATCH] AP boot support
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
# 2005/05/07 21:32:49-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx
# get AP booting working
# currently crashing in init_secondary - will fix after adding SMP
debug support
# Signed-off-by: Kip Macy <kmacy@xxxxxxxxxxx>
#
# freebsd-5.3-xen-sparse/i386-xen/include/xenfunc.h
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +4 -0
# add declaration for per-cpu clock init
#
# freebsd-5.3-xen-sparse/i386-xen/include/pmap.h
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +1 -0
# make pmap_lazyfix_action global
#
# freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +6 -1
# add IPI fields
#
# freebsd-5.3-xen-sparse/i386-xen/include/hypervisor.h
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +16 -0
# add boot_vcpu call
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/xen_machdep.c
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +0 -2
# make PANIC_IF declaration global
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/pmap.c
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +0 -1
# make pmap_lazyfix_action global
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/mp_machdep.c
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +229 -55
# add support for booting APs
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/machdep.c
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +78 -46
# do per-cpu GDT initialization up-front
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c
# 2005/05/07 21:32:47-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +15 -8
# special case AST IPI
#
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/clock.c
# 2005/05/07 21:32:46-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +60 -14
# add per-cpu clock support
#
i386-xen/clock.c | 74 ++++++++++--
i386-xen/evtchn.c | 23 ++-
i386-xen/machdep.c | 124 +++++++++++++--------
i386-xen/mp_machdep.c | 284 +++++++++++++++++++++++++++++++++++++++----------
i386-xen/pmap.c | 1
i386-xen/xen_machdep.c | 2
include/hypervisor.h | 16 ++
include/pcpu.h | 7 +
include/pmap.h | 1
include/xenfunc.h | 4
10 files changed, 409 insertions(+), 127 deletions(-)
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/clock.c
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/clock.c
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/clock.c 2005-05-08 05:04:11
-04:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/clock.c 2005-05-08 05:04:11
-04:00
@@ -87,6 +87,12 @@
/* XEN specific defines */
#include <machine/xen_intr.h>
+#include <vm/vm.h> /* needed by machine/pmap.h */
+#include <vm/pmap.h> /* needed by machine/pmap.h */
+#include <machine/pmap.h> /* needed by xen-os.h */
+#include <machine/hypervisor-ifs.h>
+#include <machine/xen-os.h> /* needed by xenfunc.h */
+#include <machine/xenfunc.h>
/*
* 32-bit time_t's can't reach leap years before 1904 or after 2036, so we
@@ -129,7 +135,15 @@
static uint32_t shadow_time_version;
static struct timeval shadow_tv;
+#define DEFINE_PER_CPU(type, name) \
+ __typeof__(type) per_cpu__##name
+
+#define per_cpu(var, cpu) (*((void)cpu, &per_cpu__##var))
+
+
static uint64_t processed_system_time;/* System time (ns) at last processing.
*/
+static DEFINE_PER_CPU(uint64_t, processed_system_time);
+
#define NS_PER_TICK (1000000000ULL/hz)
@@ -202,18 +216,19 @@
static void
clkintr(struct clockframe *frame)
{
- int64_t delta;
+ int64_t cpu_delta, delta;
+ int cpu = smp_processor_id();
long ticks = 0;
-
do {
__get_time_values_from_xen();
- delta = (int64_t)(shadow_system_time +
- xen_get_offset() * 1000 -
- processed_system_time);
+ delta = cpu_delta = (int64_t)shadow_system_time +
+ (int64_t)xen_get_offset() * 1000;
+ delta -= processed_system_time;
+ cpu_delta -= per_cpu(processed_system_time, cpu);
} while (!TIME_VALUES_UP_TO_DATE);
- if (unlikely(delta < 0)) {
+ if (unlikely(delta < 0) || unlikely(cpu_delta < 0)) {
printk("Timer ISR: Time went backwards: %lld\n", delta);
return;
}
@@ -225,15 +240,28 @@
delta -= NS_PER_TICK;
processed_system_time += NS_PER_TICK;
}
-
- if (ticks > 0) {
- if (frame)
- timer_func(frame);
-#ifdef SMP
- if (timer_func == hardclock && frame)
- forward_hardclock();
+ /* Local CPU jiffy work. */
+ while (cpu_delta >= NS_PER_TICK) {
+ cpu_delta -= NS_PER_TICK;
+ per_cpu(processed_system_time, cpu) += NS_PER_TICK;
+#if 0
+ update_process_times(user_mode(regs));
+ profile_tick(CPU_PROFILING, regs);
#endif
}
+ if (ticks > 0) {
+ if (frame) timer_func(frame);
+ }
+
+ if (cpu != 0)
+ return;
+ /*
+ * Take synchronised time from Xen once a minute if we're not
+ * synchronised ourselves, and we haven't chosen to keep an independent
+ * time base.
+ */
+
+ /* XXX TODO */
}
#include "opt_ddb.h"
@@ -429,7 +457,7 @@
* Start clocks running.
*/
void
-cpu_initclocks()
+cpu_initclocks(void)
{
int diag;
int time_irq = bind_virq_to_irq(VIRQ_TIMER);
@@ -445,7 +473,25 @@
/* initialize xen values */
__get_time_values_from_xen();
processed_system_time = shadow_system_time;
+ per_cpu(processed_system_time, 0) = processed_system_time;
+
+}
+
+#ifdef SMP
+void
+ap_cpu_initclocks(void)
+{
+ int irq;
+ int cpu = smp_processor_id();
+
+ per_cpu(processed_system_time, cpu) = shadow_system_time;
+
+ irq = bind_virq_to_irq(VIRQ_TIMER);
+ PCPU_SET(time_irq, irq);
+ PANIC_IF(intr_add_handler("clk", irq, (driver_intr_t *)clkintr,
+ NULL, INTR_TYPE_CLK | INTR_FAST, NULL));
}
+#endif
void
cpu_startprofclock(void)
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c 2005-05-08 05:04:11
-04:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/evtchn.c 2005-05-08 05:04:11
-04:00
@@ -79,9 +79,14 @@
l2 &= ~(1 << l2i);
port = (l1i << 5) + l2i;
+ irq = evtchn_to_irq[port];
+#ifdef SMP
+ if (irq == PCPU_GET(cpuast))
+ continue;
+#endif
if ( (owned = mtx_owned(&sched_lock)) != 0 )
mtx_unlock_spin_flags(&sched_lock, MTX_QUIET);
- if ( (irq = evtchn_to_irq[port]) != -1 ) {
+ if ( irq != -1 ) {
struct intsrc *isrc = intr_lookup_source(irq);
intr_execute_handlers(isrc, frame);
} else {
@@ -584,6 +589,7 @@
PCPU_GET(virq_to_irq)[i] = -1;
}
+
static void
evtchn_init(void *dummy __unused)
{
@@ -591,13 +597,6 @@
struct xenpic *xp;
struct xenpic_intsrc *pin;
- /*
- * xenpic_lock: in order to allow an interrupt to occur in a critical
- * section, to set pcpu->ipending (etc...) properly, we
- * must be able to get the icu lock, so it can't be
- * under witness.
- */
- mtx_init(&irq_mapping_update_lock, "xp", NULL, MTX_DEF);
/* XXX -- expedience hack */
PCPU_SET(virq_to_irq, (int *)&virq_to_irq[0]);
@@ -657,3 +656,11 @@
}
SYSINIT(evtchn_init, SI_SUB_INTR, SI_ORDER_ANY, evtchn_init, NULL);
+ /*
+ * xenpic_lock: in order to allow an interrupt to occur in a critical
+ * section, to set pcpu->ipending (etc...) properly, we
+ * must be able to get the icu lock, so it can't be
+ * under witness.
+ */
+
+MTX_SYSINIT(irq_mapping_update_lock, &irq_mapping_update_lock, "xp",
MTX_DEF|MTX_NOWITNESS);
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/machdep.c
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/machdep.c
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/machdep.c 2005-05-08
05:04:11 -04:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/machdep.c 2005-05-08
05:04:11 -04:00
@@ -78,6 +78,7 @@
#include <sys/sched.h>
#include <sys/sysent.h>
#include <sys/sysctl.h>
+#include <sys/smp.h>
#include <sys/ucontext.h>
#include <sys/vmmeter.h>
#include <sys/bus.h>
@@ -883,14 +884,6 @@
static void
cpu_idle_default(void)
{
-#if 0
- /*
- * we must absolutely guarentee that hlt is the
- * absolute next instruction after sti or we
- * introduce a timing window.
- */
- __asm __volatile("sti; hlt");
-#endif
idle_block();
enable_intr();
}
@@ -1376,6 +1369,7 @@
unsigned long *xen_machine_phys = ((unsigned long *)VADDR(1008, 0));
int preemptable;
int gdt_set;
+static int ncpus;
/* Linux infection */
#define PAGE_OFFSET KERNBASE
@@ -1387,6 +1381,10 @@
int i;
vm_paddr_t pdir_shadow_ma, KPTphys;
vm_offset_t *pdir_shadow;
+#ifdef SMP
+ int j;
+#endif
+
#ifdef WRITABLE_PAGETABLES
printk("using writable pagetables\n");
HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables);
@@ -1447,18 +1445,19 @@
#ifdef SMP
+#if 0
/* allocate cpu0 private page */
cpu0prvpage = (KERNBASE + (tmpindex << PAGE_SHIFT));
tmpindex++;
-
+#endif
/* allocate SMP page table */
SMPpt = (unsigned long *)(KERNBASE + (tmpindex << PAGE_SHIFT));
-
+#if 0
/* Map the private page into the SMP page table */
SMPpt[0] = vtomach(cpu0prvpage) | PG_RW | PG_M | PG_V | PG_A;
-
+#endif
/* map SMP page table RO */
- PT_SET_MA(SMPpt, vtomach(SMPpt) & ~PG_RW);
+ PT_SET_MA(SMPpt, *vtopte((vm_offset_t)SMPpt) & ~PG_RW);
/* put the page table into the page directory */
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|