2

I am trying to understand this Linux commit (commit ID 830eec24673a982bff4df85ba4d17e4a6ff201a7). It converts a spinlock to raw_spinlock. But I am not clear about why spinlock will make a wake to a blocked idle task failed here. And why a raw_spinlock can solve this problem.

I have read the Linux code and find spin_lock is just a wrapper of raw_spin_lock. And spinlock_t is a wrapper of raw_spinlock_t. It seems that they have no significant difference. I also learned that they may have difference on preemption, but I am not sure it is related to this patch.

@@ -32,7 +32,7 @@ static void write_pen_release(int val)
    sync_cache_w(&pen_release);
 }

-static DEFINE_SPINLOCK(boot_lock);
+static DEFINE_RAW_SPINLOCK(boot_lock);

 void versatile_secondary_init(unsigned int cpu)
 {
@@ -45,8 +45,8 @@ void versatile_secondary_init(unsigned int cpu)
    /*
     * Synchronise with the boot thread.
     */
-   spin_lock(&boot_lock);
-   spin_unlock(&boot_lock);
+   raw_spin_lock(&boot_lock);
+   raw_spin_unlock(&boot_lock);
 }

 int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
@@ -57,7 +57,7 @@ int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
     * Set synchronisation state between this boot processor
     * and the secondary one
     */
-   spin_lock(&boot_lock);
+   raw_spin_lock(&boot_lock);

    /*
     * This is really belt and braces; we hold unintended secondary
@@ -87,7 +87,7 @@ int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
     * now the secondary core is starting up let it run its
     * calibrations, then wait for it to finish
     */
-   spin_unlock(&boot_lock);
+   raw_spin_unlock(&boot_lock);

    return pen_release != -1 ? -ENOSYS : 0;
 }
red0ct
  • 4,840
  • 3
  • 17
  • 44
Lesterth
  • 77
  • 1
  • 6
  • You simple looking to the wrong sources to get an answer to this question. What you need is called Linux RT project, where they have a difference. Hint: find a file *include/linux/spinlock_rt.h*. – 0andriy May 24 '19 at 23:32
  • But this patch is for Linux kernel, not for RT Linux. And there is no include/linux/spinlock_rt.h. I have looked for it in Linux-5.0.6 source code. – Lesterth May 29 '19 at 11:50
  • Yes, this patch like many others have been applied in order to help with Linux RT. And I told you already, you are looking to the **wrong** repository. – 0andriy May 31 '19 at 20:15

0 Answers0