~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/mips/kernel/spinlock_test.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/init.h>
  3 #include <linux/kthread.h>
  4 #include <linux/hrtimer.h>
  5 #include <linux/fs.h>
  6 #include <linux/debugfs.h>
  7 #include <linux/export.h>
  8 #include <linux/spinlock.h>
  9 #include <asm/debug.h>
 10 
 11 static int ss_get(void *data, u64 *val)
 12 {
 13         ktime_t start, finish;
 14         int loops;
 15         int cont;
 16         DEFINE_RAW_SPINLOCK(ss_spin);
 17 
 18         loops = 1000000;
 19         cont = 1;
 20 
 21         start = ktime_get();
 22 
 23         while (cont) {
 24                 raw_spin_lock(&ss_spin);
 25                 loops--;
 26                 if (loops == 0)
 27                         cont = 0;
 28                 raw_spin_unlock(&ss_spin);
 29         }
 30 
 31         finish = ktime_get();
 32 
 33         *val = ktime_us_delta(finish, start);
 34 
 35         return 0;
 36 }
 37 
 38 DEFINE_SIMPLE_ATTRIBUTE(fops_ss, ss_get, NULL, "%llu\n");
 39 
 40 
 41 
 42 struct spin_multi_state {
 43         raw_spinlock_t lock;
 44         atomic_t start_wait;
 45         atomic_t enter_wait;
 46         atomic_t exit_wait;
 47         int loops;
 48 };
 49 
 50 struct spin_multi_per_thread {
 51         struct spin_multi_state *state;
 52         ktime_t start;
 53 };
 54 
 55 static int multi_other(void *data)
 56 {
 57         int loops;
 58         int cont;
 59         struct spin_multi_per_thread *pt = data;
 60         struct spin_multi_state *s = pt->state;
 61 
 62         loops = s->loops;
 63         cont = 1;
 64 
 65         atomic_dec(&s->enter_wait);
 66 
 67         while (atomic_read(&s->enter_wait))
 68                 ; /* spin */
 69 
 70         pt->start = ktime_get();
 71 
 72         atomic_dec(&s->start_wait);
 73 
 74         while (atomic_read(&s->start_wait))
 75                 ; /* spin */
 76 
 77         while (cont) {
 78                 raw_spin_lock(&s->lock);
 79                 loops--;
 80                 if (loops == 0)
 81                         cont = 0;
 82                 raw_spin_unlock(&s->lock);
 83         }
 84 
 85         atomic_dec(&s->exit_wait);
 86         while (atomic_read(&s->exit_wait))
 87                 ; /* spin */
 88         return 0;
 89 }
 90 
 91 static int multi_get(void *data, u64 *val)
 92 {
 93         ktime_t finish;
 94         struct spin_multi_state ms;
 95         struct spin_multi_per_thread t1, t2;
 96 
 97         ms.lock = __RAW_SPIN_LOCK_UNLOCKED("multi_get");
 98         ms.loops = 1000000;
 99 
100         atomic_set(&ms.start_wait, 2);
101         atomic_set(&ms.enter_wait, 2);
102         atomic_set(&ms.exit_wait, 2);
103         t1.state = &ms;
104         t2.state = &ms;
105 
106         kthread_run(multi_other, &t2, "multi_get");
107 
108         multi_other(&t1);
109 
110         finish = ktime_get();
111 
112         *val = ktime_us_delta(finish, t1.start);
113 
114         return 0;
115 }
116 
117 DEFINE_SIMPLE_ATTRIBUTE(fops_multi, multi_get, NULL, "%llu\n");
118 
119 static int __init spinlock_test(void)
120 {
121         debugfs_create_file("spin_single", S_IRUGO, mips_debugfs_dir, NULL,
122                             &fops_ss);
123         debugfs_create_file("spin_multi", S_IRUGO, mips_debugfs_dir, NULL,
124                             &fops_multi);
125         return 0;
126 }
127 device_initcall(spinlock_test);
128 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp