From: Robert Love <rml@tech9.net>
To: marcelo@conectiva.com.br
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] 2.4: introduce get_cpu() and put_cpu()
Date: 06 Oct 2002 15:45:47 -0400 [thread overview]
Message-ID: <1033933547.743.4472.camel@phantasy> (raw)
Master Marcelo,
In 2.5, it is unsafe to assume the current processor does not change out
from under you - thus you must be atomic when calling
smp_processor_id(). We introduced the get_cpu() and put_cpu() methods
to provide a safe way to access the current processor.
This patch back-ports those interfaces to 2.4. Note they do nothing
special: get_cpu() simply returns smp_processor_id() and put_cpu() is a
no-op. But this will allow easier back-porting from 2.5 and common
code-base for drivers, etc. It also does not hurt to be explicit that
you do not want the processor to change.
As an example, I converted one use of smp_processor_id() to the new
interface.
Patch is against 2.4.20-pre9, please apply.
Robert Love
diff -urN linux-2.4.20-pre9/arch/i386/kernel/ioport.c linux/arch/i386/kernel/ioport.c
--- linux-2.4.20-pre9/arch/i386/kernel/ioport.c 2002-10-06 14:58:01.000000000 -0400
+++ linux/arch/i386/kernel/ioport.c 2002-10-06 15:21:04.000000000 -0400
@@ -55,12 +55,15 @@
asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
struct thread_struct * t = ¤t->thread;
- struct tss_struct * tss = init_tss + smp_processor_id();
+ struct tss_struct * tss;
if ((from + num <= from) || (from + num > IO_BITMAP_SIZE*32))
return -EINVAL;
if (turn_on && !capable(CAP_SYS_RAWIO))
return -EPERM;
+
+ tss = init_tss + get_cpu();
+
/*
* If it's the first ioperm() call in this thread's lifetime, set the
* IO bitmap up. ioperm() is much less timing critical than clone(),
diff -urN linux-2.4.20-pre9/include/linux/smp.h linux/include/linux/smp.h
--- linux-2.4.20-pre9/include/linux/smp.h 2002-10-06 14:57:20.000000000 -0400
+++ linux/include/linux/smp.h 2002-10-06 15:11:00.000000000 -0400
@@ -87,5 +87,9 @@
#define smp_call_function(func,info,retry,wait) ({ 0; })
#define cpu_online_map 1
-#endif
-#endif
+#endif /* !CONFIG_SMP */
+
+#define get_cpu() smp_processor_id()
+#define put_cpu() do { } while(0)
+
+#endif /* __LINUX_SMP_H */
next reply other threads:[~2002-10-06 19:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-06 19:45 Robert Love [this message]
2002-10-06 20:36 ` [PATCH] 2.4: introduce get_cpu() and put_cpu() Kasper Dupont
2002-10-06 21:08 ` Robert Love
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=1033933547.743.4472.camel@phantasy \
--to=rml@tech9.net \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo@conectiva.com.br \
/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