From: Brent Casavant <bcasavan@sgi.com>
To: linux-ia64@vger.kernel.org
Subject: [PATCH] SN2 user-MMIO CPU migration
Date: Tue, 24 Jan 2006 00:33:39 +0000 [thread overview]
Message-ID: <20060123180530.N74549@chenjesu.americas.sgi.com> (raw)
In-Reply-To: <20060118163305.Y42462@chenjesu.americas.sgi.com>
Take 2.
On SN2, MMIO writes which are issued from separate processors are not
guaranteed to arrive in any particular order at the IO hardware. When
performing such writes from the kernel this is not a problem, as a
kernel thread will not migrate to another CPU during execution, and
mmiowb() calls can guarantee write ordering when control of the IO
resource is allowed to move between threads.
However, when MMIO writes can be performed from user space (e.g. DRM)
there are no such guarantees and mechanisms, as the process may
context-switch at any time, and may migrate to a different CPU as part
of the switch. For such programs/hardware to operate correctly, it is
required that the MMIO writes from the old CPU be accepted by the IO
hardware before subsequent writes from the new CPU can be issued.
The following patch implements this behavior on SN2 by waiting for a
Shub register to indicate that these writes have been accepted (the
non-SN2 case is a no-op). This is placed in the context switch-in
path, and only performs the wait when the newly scheduled task changes
CPUs.
Signed-off-by: Brent Casavant <bcasavan@sgi.com>
arch/ia64/sn/kernel/setup.c | 8 +++++---
arch/ia64/sn/kernel/sn2/sn2_smp.c | 33 ++++++++++++++++++++++++++++++++-
include/asm-ia64/machvec.h | 12 ++++++++++++
include/asm-ia64/machvec_sn2.h | 4 +++-
include/asm-ia64/system.h | 1 +
include/asm-ia64/thread_info.h | 10 ++++++++++
6 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/arch/ia64/sn/kernel/setup.c b/arch/ia64/sn/kernel/setup.c
index e510dce..9a52dfa 100644
--- a/arch/ia64/sn/kernel/setup.c
+++ b/arch/ia64/sn/kernel/setup.c
@@ -3,7 +3,7 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
- * Copyright (C) 1999,2001-2005 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 1999,2001-2006 Silicon Graphics, Inc. All rights reserved.
*/
#include <linux/config.h>
@@ -654,8 +654,10 @@ void __init sn_cpu_init(void)
SH2_PIO_WRITE_STATUS_1, SH2_PIO_WRITE_STATUS_3};
u64 *pio;
pio = is_shub1() ? pio1 : pio2;
- pda->pio_write_status_addr = (volatile unsigned long *) LOCAL_MMR_ADDR(pio[slice]);
- pda->pio_write_status_val = is_shub1() ? SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
+ pda->pio_write_status_addr = (volatile unsigned long *)
+ GLOBAL_MMR_ADDR(nasid, pio[slice]);
+ pda->pio_write_status_val = is_shub1() ?
+ SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK : 0;
}
/*
diff --git a/arch/ia64/sn/kernel/sn2/sn2_smp.c b/arch/ia64/sn/kernel/sn2/sn2_smp.c
index 471bbaa..1cca3f2 100644
--- a/arch/ia64/sn/kernel/sn2/sn2_smp.c
+++ b/arch/ia64/sn/kernel/sn2/sn2_smp.c
@@ -5,7 +5,7 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
- * Copyright (C) 2000-2005 Silicon Graphics, Inc. All rights reserved.
+ * Copyright (C) 2000-2006 Silicon Graphics, Inc. All rights reserved.
*/
#include <linux/init.h>
@@ -169,6 +169,37 @@ static inline unsigned long wait_piowc(v
return ws;
}
+/**
+ * sn_switch_from - SN-specific migrate-from actions
+ * @task: Task being switched to new CPU
+ *
+ * SN2 PIO writes from separate CPUs are not guaranteed to arrive in order.
+ * Context switching user threads which have memory-mapped MMIO may cause
+ * PIOs to issue from seperate CPUs, thus the PIO writes must be drained
+ * from the previous CPU's Shub before execution resumes on the new CPU.
+ */
+void sn_switch_from(struct task_struct *task)
+{
+ __u32 *piowr_cpu = &task_thread_info(task)->sn2_piowr_cpu;
+ __u32 this_cpu = task_cpu(task);
+ pda_t *piowr_pda;
+ volatile unsigned long *adr;
+ unsigned long val;
+
+ if (likely(this_cpu = *piowr_cpu))
+ return;
+
+ /* Drain PIO writes from old CPU's Shub */
+ piowr_pda = pdacpu(*piowr_cpu);
+ adr = piowr_pda->pio_write_status_addr;
+ val = piowr_pda->pio_write_status_val;
+ while ((*adr & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK) != val)
+ cpu_relax();
+
+ /* Next time drain this CPU's Shub */
+ *piowr_cpu = this_cpu;
+}
+
void sn_tlb_migrate_finish(struct mm_struct *mm)
{
if (mm = current->mm)
diff --git a/include/asm-ia64/machvec.h b/include/asm-ia64/machvec.h
index ca5ea99..9b54073 100644
--- a/include/asm-ia64/machvec.h
+++ b/include/asm-ia64/machvec.h
@@ -34,6 +34,7 @@ typedef int ia64_mv_pci_legacy_read_t (s
u8 size);
typedef int ia64_mv_pci_legacy_write_t (struct pci_bus *, u16 port, u32 val,
u8 size);
+typedef void ia64_mv_switch_from_t(struct task_struct * task);
/* DMA-mapping interface: */
typedef void ia64_mv_dma_init (void);
@@ -85,6 +86,11 @@ machvec_noop_mm (struct mm_struct *mm)
{
}
+static inline void
+machvec_noop_task (struct task_struct *task)
+{
+}
+
extern void machvec_setup (char **);
extern void machvec_timer_interrupt (int, void *, struct pt_regs *);
extern void machvec_dma_sync_single (struct device *, dma_addr_t, size_t, int);
@@ -146,6 +152,7 @@ extern void machvec_tlb_migrate_finish (
# define platform_readw_relaxed ia64_mv.readw_relaxed
# define platform_readl_relaxed ia64_mv.readl_relaxed
# define platform_readq_relaxed ia64_mv.readq_relaxed
+# define platform_switch_from ia64_mv.switch_from
# endif
/* __attribute__((__aligned__(16))) is required to make size of the
@@ -194,6 +201,7 @@ struct ia64_machine_vector {
ia64_mv_readw_relaxed_t *readw_relaxed;
ia64_mv_readl_relaxed_t *readl_relaxed;
ia64_mv_readq_relaxed_t *readq_relaxed;
+ ia64_mv_switch_from_t *switch_from;
} __attribute__((__aligned__(16))); /* align attrib? see above comment */
#define MACHVEC_INIT(name) \
@@ -238,6 +246,7 @@ struct ia64_machine_vector {
platform_readw_relaxed, \
platform_readl_relaxed, \
platform_readq_relaxed, \
+ platform_switch_from, \
}
extern struct ia64_machine_vector ia64_mv;
@@ -386,5 +395,8 @@ extern ia64_mv_dma_supported swiotlb_dm
#ifndef platform_readq_relaxed
# define platform_readq_relaxed __ia64_readq_relaxed
#endif
+#ifndef platform_switch_from
+# define platform_switch_from machvec_noop_task
+#endif
#endif /* _ASM_IA64_MACHVEC_H */
diff --git a/include/asm-ia64/machvec_sn2.h b/include/asm-ia64/machvec_sn2.h
index e1b6cd6..110dc54 100644
--- a/include/asm-ia64/machvec_sn2.h
+++ b/include/asm-ia64/machvec_sn2.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002-2003 Silicon Graphics, Inc. All Rights Reserved.
+ * Copyright (c) 2002-2003,2006 Silicon Graphics, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License
@@ -71,6 +71,7 @@ extern ia64_mv_dma_sync_single_for_devic
extern ia64_mv_dma_sync_sg_for_device sn_dma_sync_sg_for_device;
extern ia64_mv_dma_mapping_error sn_dma_mapping_error;
extern ia64_mv_dma_supported sn_dma_supported;
+extern ia64_mv_switch_from_t sn_switch_from;
/*
* This stuff has dual use!
@@ -120,6 +121,7 @@ extern ia64_mv_dma_supported sn_dma_sup
#define platform_dma_sync_sg_for_device sn_dma_sync_sg_for_device
#define platform_dma_mapping_error sn_dma_mapping_error
#define platform_dma_supported sn_dma_supported
+#define platform_switch_from sn_switch_from
#include <asm/sn/io.h>
diff --git a/include/asm-ia64/system.h b/include/asm-ia64/system.h
index 80c5a23..0508327 100644
--- a/include/asm-ia64/system.h
+++ b/include/asm-ia64/system.h
@@ -243,6 +243,7 @@ extern void ia64_load_extra (struct task
(prev)->thread.flags |= IA64_THREAD_FPH_VALID; \
__ia64_save_fpu((prev)->thread.fph); \
} \
+ platform_switch_from(next); \
__switch_to(prev, next, last); \
} while (0)
#else
diff --git a/include/asm-ia64/thread_info.h b/include/asm-ia64/thread_info.h
index 1d6518f..c63494d 100644
--- a/include/asm-ia64/thread_info.h
+++ b/include/asm-ia64/thread_info.h
@@ -36,10 +36,19 @@ struct thread_info {
unsigned long start_time;
pid_t pid;
} sigdelayed; /* Saved information for TIF_SIGDELAYED */
+#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
+ __u32 sn2_piowr_cpu; /* CPU needing PIO write drain */
+#endif
};
#define THREAD_SIZE KERNEL_STACK_SIZE
+#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
+#define INIT_TI_SN2_PIOWR_CPU .sn2_piowr_cpu = 0,
+#else
+#define INIT_TI_SN2_PIOWR_CPU
+#endif
+
#define INIT_THREAD_INFO(tsk) \
{ \
.task = &tsk, \
@@ -51,6 +60,7 @@ struct thread_info {
.restart_block = { \
.fn = do_no_restart_syscall, \
}, \
+ INIT_TI_SN2_PIOWR_CPU \
}
#ifndef ASM_OFFSETS_C
next prev parent reply other threads:[~2006-01-24 0:33 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-20 0:06 [PATCH] SN2 user-MMIO CPU migration Brent Casavant
2006-01-20 2:18 ` Jesse Barnes
2006-01-20 6:47 ` Brent Casavant
2006-01-20 17:36 ` Jesse Barnes
2006-01-20 20:01 ` Brent Casavant
2006-01-20 13:26 ` Jack Steiner
2006-01-20 17:31 ` Jesse Barnes
2006-01-20 19:00 ` Jack Steiner
2006-01-20 8:36 ` Ingo Molnar
2006-01-20 16:14 ` Brent Casavant
2006-01-24 0:33 ` Brent Casavant [this message]
2006-01-24 0:48 ` Luck, Tony
2006-01-24 1:23 ` Brent Casavant
2006-01-24 1:42 ` Keith Owens
2006-01-24 3:41 ` Grant Grundler
2006-01-24 6:30 ` Brent Casavant
2006-01-24 6:41 ` Brent Casavant
2006-01-24 7:04 ` Grant Grundler
2006-01-24 9:02 ` Ingo Molnar
2006-01-24 9:14 ` Jes Sorensen
2006-01-24 12:10 ` Robin Holt
2006-01-24 16:40 ` Grant Grundler
2006-01-24 16:52 ` Brent Casavant
2006-01-24 16:57 ` Brent Casavant
2006-01-24 17:00 ` Robin Holt
2006-01-24 17:33 ` Luck, Tony
2006-01-24 18:42 ` Grant Grundler
2006-01-24 21:12 ` Brent Casavant
2006-01-24 21:41 ` Ingo Molnar
2006-01-24 21:43 ` Chen, Kenneth W
2006-01-24 21:51 ` Luck, Tony
2006-01-24 22:04 ` Brent Casavant
2006-01-24 22:07 ` Chen, Kenneth W
2006-01-24 22:12 ` Brent Casavant
2006-01-24 22:19 ` Chen, Kenneth W
2006-01-24 22:31 ` Chen, Kenneth W
2006-01-24 22:41 ` Brent Casavant
2006-01-24 23:25 ` Chen, Kenneth W
2006-01-24 23:28 ` Brent Casavant
2006-01-24 23:36 ` Chen, Kenneth W
2006-01-24 23:54 ` Brent Casavant
2006-01-25 0:10 ` Brent Casavant
2006-01-25 0:29 ` Chen, Kenneth W
2006-01-25 6:27 ` Keith Owens
2006-01-25 9:04 ` Chen, Kenneth W
2006-01-25 9:24 ` Chen, Kenneth W
2006-01-25 17:04 ` Brent Casavant
2006-01-25 17:45 ` Brent Casavant
2006-01-25 17:48 ` Brent Casavant
2006-01-25 19:01 ` Chen, Kenneth W
2006-01-25 19:15 ` Brent Casavant
2006-01-25 19:43 ` Jack Steiner
2006-01-25 22:49 ` Brent Casavant
2006-01-25 23:09 ` Brent Casavant
2006-01-25 23:49 ` Brent Casavant
2006-01-25 23:56 ` Chen, Kenneth W
2006-01-26 1:06 ` Luck, Tony
2006-01-26 1:31 ` Prarit Bhargava
2006-01-26 2:43 ` Keith Owens
2006-01-26 4:40 ` Brent Casavant
2006-01-26 16:29 ` Brent Casavant
2006-01-26 16:41 ` Prarit Bhargava
2006-01-26 19:29 ` Brent Casavant
2006-01-26 19:54 ` Luck, Tony
2006-01-26 20:28 ` Brent Casavant
2006-01-26 21:05 ` Luck, Tony
2006-01-26 21:34 ` Prarit Bhargava
2006-01-26 22:11 ` Luck, Tony
2006-01-26 23:08 ` Luck, Tony
2006-01-26 23:21 ` Prarit Bhargava
2006-01-26 23:44 ` Prarit Bhargava
2006-01-27 0:07 ` Chen, Kenneth W
2006-01-27 14:01 ` Prarit Bhargava
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060123180530.N74549@chenjesu.americas.sgi.com \
--to=bcasavan@sgi.com \
--cc=linux-ia64@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox