The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Nigel Cunningham <ncunningham@linuxmail.org>,
	kernel list <linux-kernel@vger.kernel.org>
Subject: suspend2 with smp
Date: Thu, 12 Aug 2004 23:56:44 +0200	[thread overview]
Message-ID: <20040812215644.GA20021@elf.ucw.cz> (raw)

Hi!

At some point I claimed that SMP support in suspend2 is "probably
broken". I guess I should post more data:

It is broken in theory.

+/*
+ * Save and restore processor state for secondary processors.
+ * IRQs (and therefore preemption) are already disabled
+ * when we enter here (IPI).
+ */
+
+void smp_suspend2_lowlevel(void * info)
+{
+       smp_mb();
+       barrier();
+       if (now_resuming) {
+               __asm__( "movl %%ecx,%%cr3\n" ::"c"(__pa(swsusp_pg_dir)));
+
+               kernel_fpu_begin();
+               atomic_inc(&suspend_cpu_counter);
+               smp_mb();
+               barrier();
#+               while ((software_suspend_state & SOFTWARE_SUSPEND_FREEZE_SMP) ||
#+                       (atomic_read(&suspend_cpu_counter) != smp_processor_id())) {
#+                       cpu_relax();
#+                       smp_mb();
+               }
+               my_saved_context = (unsigned char *) (suspend2_saved_contexts + smp_processor_id());
+               for (loop = sizeof(struct suspend2_saved_context); loop--; loop)
+                       *(((unsigned char *) &suspend2_saved_context) + loop - 1) = *(my_saved_context + loop - 1);
+               restore_processor_context();
+               FLUSH_LOCAL_TLB();
+               atomic_dec(&suspend_cpu_counter);

CPU is basically looping in loop marked by #, while its memory is
being overwriten. Now, the code probably works in practice, but it
should be really written in assembly so that compiler can not do
something stupid.

Compilers are not designed to deal with their stack (etc) randomly
overwritten, so compiler may do anything it wants here. I see that -O0
may help a lot here, but it simply is not the right thing to do.

At least /* FIXME: should be rewritten to assembly */ should be added there.

								Pavel
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

             reply	other threads:[~2004-08-12 22:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-12 21:56 Pavel Machek [this message]
2004-08-12 22:23 ` suspend2 with smp Nigel Cunningham

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=20040812215644.GA20021@elf.ucw.cz \
    --to=pavel@ucw.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncunningham@linuxmail.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