bL_switcher.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /*
  2. * arch/arm/common/bL_switcher.c -- big.LITTLE cluster switcher core driver
  3. *
  4. * Created by: Nicolas Pitre, March 2012
  5. * Copyright: (C) 2012-2013 Linaro Limited
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/sched.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/cpu_pm.h>
  17. #include <linux/cpu.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/kthread.h>
  20. #include <linux/wait.h>
  21. #include <linux/clockchips.h>
  22. #include <linux/hrtimer.h>
  23. #include <linux/tick.h>
  24. #include <linux/notifier.h>
  25. #include <linux/mm.h>
  26. #include <linux/mutex.h>
  27. #include <linux/string.h>
  28. #include <linux/sysfs.h>
  29. #include <linux/irqchip/arm-gic.h>
  30. #include <linux/moduleparam.h>
  31. #include <asm/smp_plat.h>
  32. #include <asm/suspend.h>
  33. #include <asm/mcpm.h>
  34. #include <asm/bL_switcher.h>
  35. /*
  36. * Use our own MPIDR accessors as the generic ones in asm/cputype.h have
  37. * __attribute_const__ and we don't want the compiler to assume any
  38. * constness here as the value _does_ change along some code paths.
  39. */
  40. static int read_mpidr(void)
  41. {
  42. unsigned int id;
  43. asm volatile ("mrc p15, 0, %0, c0, c0, 5" : "=r" (id));
  44. return id & MPIDR_HWID_BITMASK;
  45. }
  46. /*
  47. * bL switcher core code.
  48. */
  49. static void bL_do_switch(void *_unused)
  50. {
  51. unsigned ib_mpidr, ib_cpu, ib_cluster;
  52. pr_debug("%s\n", __func__);
  53. ib_mpidr = cpu_logical_map(smp_processor_id());
  54. ib_cpu = MPIDR_AFFINITY_LEVEL(ib_mpidr, 0);
  55. ib_cluster = MPIDR_AFFINITY_LEVEL(ib_mpidr, 1);
  56. /*
  57. * Our state has been saved at this point. Let's release our
  58. * inbound CPU.
  59. */
  60. mcpm_set_entry_vector(ib_cpu, ib_cluster, cpu_resume);
  61. sev();
  62. /*
  63. * From this point, we must assume that our counterpart CPU might
  64. * have taken over in its parallel world already, as if execution
  65. * just returned from cpu_suspend(). It is therefore important to
  66. * be very careful not to make any change the other guy is not
  67. * expecting. This is why we need stack isolation.
  68. *
  69. * Fancy under cover tasks could be performed here. For now
  70. * we have none.
  71. */
  72. /* Let's put ourself down. */
  73. mcpm_cpu_power_down();
  74. /* should never get here */
  75. BUG();
  76. }
  77. /*
  78. * Stack isolation. To ensure 'current' remains valid, we just use another
  79. * piece of our thread's stack space which should be fairly lightly used.
  80. * The selected area starts just above the thread_info structure located
  81. * at the very bottom of the stack, aligned to a cache line, and indexed
  82. * with the cluster number.
  83. */
  84. #define STACK_SIZE 512
  85. extern void call_with_stack(void (*fn)(void *), void *arg, void *sp);
  86. static int bL_switchpoint(unsigned long _arg)
  87. {
  88. unsigned int mpidr = read_mpidr();
  89. unsigned int clusterid = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  90. void *stack = current_thread_info() + 1;
  91. stack = PTR_ALIGN(stack, L1_CACHE_BYTES);
  92. stack += clusterid * STACK_SIZE + STACK_SIZE;
  93. call_with_stack(bL_do_switch, (void *)_arg, stack);
  94. BUG();
  95. }
  96. /*
  97. * Generic switcher interface
  98. */
  99. static unsigned int bL_gic_id[MAX_CPUS_PER_CLUSTER][MAX_NR_CLUSTERS];
  100. static int bL_switcher_cpu_pairing[NR_CPUS];
  101. /*
  102. * bL_switch_to - Switch to a specific cluster for the current CPU
  103. * @new_cluster_id: the ID of the cluster to switch to.
  104. *
  105. * This function must be called on the CPU to be switched.
  106. * Returns 0 on success, else a negative status code.
  107. */
  108. static int bL_switch_to(unsigned int new_cluster_id)
  109. {
  110. unsigned int mpidr, this_cpu, that_cpu;
  111. unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;
  112. struct tick_device *tdev;
  113. enum clock_event_mode tdev_mode;
  114. int ret;
  115. this_cpu = smp_processor_id();
  116. ob_mpidr = read_mpidr();
  117. ob_cpu = MPIDR_AFFINITY_LEVEL(ob_mpidr, 0);
  118. ob_cluster = MPIDR_AFFINITY_LEVEL(ob_mpidr, 1);
  119. BUG_ON(cpu_logical_map(this_cpu) != ob_mpidr);
  120. if (new_cluster_id == ob_cluster)
  121. return 0;
  122. that_cpu = bL_switcher_cpu_pairing[this_cpu];
  123. ib_mpidr = cpu_logical_map(that_cpu);
  124. ib_cpu = MPIDR_AFFINITY_LEVEL(ib_mpidr, 0);
  125. ib_cluster = MPIDR_AFFINITY_LEVEL(ib_mpidr, 1);
  126. pr_debug("before switch: CPU %d MPIDR %#x -> %#x\n",
  127. this_cpu, ob_mpidr, ib_mpidr);
  128. /* Close the gate for our entry vectors */
  129. mcpm_set_entry_vector(ob_cpu, ob_cluster, NULL);
  130. mcpm_set_entry_vector(ib_cpu, ib_cluster, NULL);
  131. /*
  132. * Let's wake up the inbound CPU now in case it requires some delay
  133. * to come online, but leave it gated in our entry vector code.
  134. */
  135. ret = mcpm_cpu_power_up(ib_cpu, ib_cluster);
  136. if (ret) {
  137. pr_err("%s: mcpm_cpu_power_up() returned %d\n", __func__, ret);
  138. return ret;
  139. }
  140. /*
  141. * From this point we are entering the switch critical zone
  142. * and can't take any interrupts anymore.
  143. */
  144. local_irq_disable();
  145. local_fiq_disable();
  146. /* redirect GIC's SGIs to our counterpart */
  147. gic_migrate_target(bL_gic_id[ib_cpu][ib_cluster]);
  148. /*
  149. * Raise a SGI on the inbound CPU to make sure it doesn't stall
  150. * in a possible WFI, such as in mcpm_power_down().
  151. */
  152. arch_send_wakeup_ipi_mask(cpumask_of(this_cpu));
  153. tdev = tick_get_device(this_cpu);
  154. if (tdev && !cpumask_equal(tdev->evtdev->cpumask, cpumask_of(this_cpu)))
  155. tdev = NULL;
  156. if (tdev) {
  157. tdev_mode = tdev->evtdev->mode;
  158. clockevents_set_mode(tdev->evtdev, CLOCK_EVT_MODE_SHUTDOWN);
  159. }
  160. ret = cpu_pm_enter();
  161. /* we can not tolerate errors at this point */
  162. if (ret)
  163. panic("%s: cpu_pm_enter() returned %d\n", __func__, ret);
  164. /* Swap the physical CPUs in the logical map for this logical CPU. */
  165. cpu_logical_map(this_cpu) = ib_mpidr;
  166. cpu_logical_map(that_cpu) = ob_mpidr;
  167. /* Let's do the actual CPU switch. */
  168. ret = cpu_suspend(0, bL_switchpoint);
  169. if (ret > 0)
  170. panic("%s: cpu_suspend() returned %d\n", __func__, ret);
  171. /* We are executing on the inbound CPU at this point */
  172. mpidr = read_mpidr();
  173. pr_debug("after switch: CPU %d MPIDR %#x\n", this_cpu, mpidr);
  174. BUG_ON(mpidr != ib_mpidr);
  175. mcpm_cpu_powered_up();
  176. ret = cpu_pm_exit();
  177. if (tdev) {
  178. clockevents_set_mode(tdev->evtdev, tdev_mode);
  179. clockevents_program_event(tdev->evtdev,
  180. tdev->evtdev->next_event, 1);
  181. }
  182. local_fiq_enable();
  183. local_irq_enable();
  184. if (ret)
  185. pr_err("%s exiting with error %d\n", __func__, ret);
  186. return ret;
  187. }
  188. struct bL_thread {
  189. struct task_struct *task;
  190. wait_queue_head_t wq;
  191. int wanted_cluster;
  192. struct completion started;
  193. };
  194. static struct bL_thread bL_threads[NR_CPUS];
  195. static int bL_switcher_thread(void *arg)
  196. {
  197. struct bL_thread *t = arg;
  198. struct sched_param param = { .sched_priority = 1 };
  199. int cluster;
  200. sched_setscheduler_nocheck(current, SCHED_FIFO, &param);
  201. complete(&t->started);
  202. do {
  203. if (signal_pending(current))
  204. flush_signals(current);
  205. wait_event_interruptible(t->wq,
  206. t->wanted_cluster != -1 ||
  207. kthread_should_stop());
  208. cluster = xchg(&t->wanted_cluster, -1);
  209. if (cluster != -1)
  210. bL_switch_to(cluster);
  211. } while (!kthread_should_stop());
  212. return 0;
  213. }
  214. static struct task_struct *bL_switcher_thread_create(int cpu, void *arg)
  215. {
  216. struct task_struct *task;
  217. task = kthread_create_on_node(bL_switcher_thread, arg,
  218. cpu_to_node(cpu), "kswitcher_%d", cpu);
  219. if (!IS_ERR(task)) {
  220. kthread_bind(task, cpu);
  221. wake_up_process(task);
  222. } else
  223. pr_err("%s failed for CPU %d\n", __func__, cpu);
  224. return task;
  225. }
  226. /*
  227. * bL_switch_request - Switch to a specific cluster for the given CPU
  228. *
  229. * @cpu: the CPU to switch
  230. * @new_cluster_id: the ID of the cluster to switch to.
  231. *
  232. * This function causes a cluster switch on the given CPU by waking up
  233. * the appropriate switcher thread. This function may or may not return
  234. * before the switch has occurred.
  235. */
  236. int bL_switch_request(unsigned int cpu, unsigned int new_cluster_id)
  237. {
  238. struct bL_thread *t;
  239. if (cpu >= ARRAY_SIZE(bL_threads)) {
  240. pr_err("%s: cpu %d out of bounds\n", __func__, cpu);
  241. return -EINVAL;
  242. }
  243. t = &bL_threads[cpu];
  244. if (IS_ERR(t->task))
  245. return PTR_ERR(t->task);
  246. if (!t->task)
  247. return -ESRCH;
  248. t->wanted_cluster = new_cluster_id;
  249. wake_up(&t->wq);
  250. return 0;
  251. }
  252. EXPORT_SYMBOL_GPL(bL_switch_request);
  253. /*
  254. * Activation and configuration code.
  255. */
  256. static DEFINE_MUTEX(bL_switcher_activation_lock);
  257. static BLOCKING_NOTIFIER_HEAD(bL_activation_notifier);
  258. static unsigned int bL_switcher_active;
  259. static unsigned int bL_switcher_cpu_original_cluster[NR_CPUS];
  260. static cpumask_t bL_switcher_removed_logical_cpus;
  261. int bL_switcher_register_notifier(struct notifier_block *nb)
  262. {
  263. return blocking_notifier_chain_register(&bL_activation_notifier, nb);
  264. }
  265. EXPORT_SYMBOL_GPL(bL_switcher_register_notifier);
  266. int bL_switcher_unregister_notifier(struct notifier_block *nb)
  267. {
  268. return blocking_notifier_chain_unregister(&bL_activation_notifier, nb);
  269. }
  270. EXPORT_SYMBOL_GPL(bL_switcher_unregister_notifier);
  271. static int bL_activation_notify(unsigned long val)
  272. {
  273. int ret;
  274. ret = blocking_notifier_call_chain(&bL_activation_notifier, val, NULL);
  275. if (ret & NOTIFY_STOP_MASK)
  276. pr_err("%s: notifier chain failed with status 0x%x\n",
  277. __func__, ret);
  278. return notifier_to_errno(ret);
  279. }
  280. static void bL_switcher_restore_cpus(void)
  281. {
  282. int i;
  283. for_each_cpu(i, &bL_switcher_removed_logical_cpus)
  284. cpu_up(i);
  285. }
  286. static int bL_switcher_halve_cpus(void)
  287. {
  288. int i, j, cluster_0, gic_id, ret;
  289. unsigned int cpu, cluster, mask;
  290. cpumask_t available_cpus;
  291. /* First pass to validate what we have */
  292. mask = 0;
  293. for_each_online_cpu(i) {
  294. cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0);
  295. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 1);
  296. if (cluster >= 2) {
  297. pr_err("%s: only dual cluster systems are supported\n", __func__);
  298. return -EINVAL;
  299. }
  300. if (WARN_ON(cpu >= MAX_CPUS_PER_CLUSTER))
  301. return -EINVAL;
  302. mask |= (1 << cluster);
  303. }
  304. if (mask != 3) {
  305. pr_err("%s: no CPU pairing possible\n", __func__);
  306. return -EINVAL;
  307. }
  308. /*
  309. * Now let's do the pairing. We match each CPU with another CPU
  310. * from a different cluster. To get a uniform scheduling behavior
  311. * without fiddling with CPU topology and compute capacity data,
  312. * we'll use logical CPUs initially belonging to the same cluster.
  313. */
  314. memset(bL_switcher_cpu_pairing, -1, sizeof(bL_switcher_cpu_pairing));
  315. cpumask_copy(&available_cpus, cpu_online_mask);
  316. cluster_0 = -1;
  317. for_each_cpu(i, &available_cpus) {
  318. int match = -1;
  319. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 1);
  320. if (cluster_0 == -1)
  321. cluster_0 = cluster;
  322. if (cluster != cluster_0)
  323. continue;
  324. cpumask_clear_cpu(i, &available_cpus);
  325. for_each_cpu(j, &available_cpus) {
  326. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(j), 1);
  327. /*
  328. * Let's remember the last match to create "odd"
  329. * pairings on purpose in order for other code not
  330. * to assume any relation between physical and
  331. * logical CPU numbers.
  332. */
  333. if (cluster != cluster_0)
  334. match = j;
  335. }
  336. if (match != -1) {
  337. bL_switcher_cpu_pairing[i] = match;
  338. cpumask_clear_cpu(match, &available_cpus);
  339. pr_info("CPU%d paired with CPU%d\n", i, match);
  340. }
  341. }
  342. /*
  343. * Now we disable the unwanted CPUs i.e. everything that has no
  344. * pairing information (that includes the pairing counterparts).
  345. */
  346. cpumask_clear(&bL_switcher_removed_logical_cpus);
  347. for_each_online_cpu(i) {
  348. cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0);
  349. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 1);
  350. /* Let's take note of the GIC ID for this CPU */
  351. gic_id = gic_get_cpu_id(i);
  352. if (gic_id < 0) {
  353. pr_err("%s: bad GIC ID for CPU %d\n", __func__, i);
  354. bL_switcher_restore_cpus();
  355. return -EINVAL;
  356. }
  357. bL_gic_id[cpu][cluster] = gic_id;
  358. pr_info("GIC ID for CPU %u cluster %u is %u\n",
  359. cpu, cluster, gic_id);
  360. if (bL_switcher_cpu_pairing[i] != -1) {
  361. bL_switcher_cpu_original_cluster[i] = cluster;
  362. continue;
  363. }
  364. ret = cpu_down(i);
  365. if (ret) {
  366. bL_switcher_restore_cpus();
  367. return ret;
  368. }
  369. cpumask_set_cpu(i, &bL_switcher_removed_logical_cpus);
  370. }
  371. return 0;
  372. }
  373. static int bL_switcher_enable(void)
  374. {
  375. int cpu, ret;
  376. mutex_lock(&bL_switcher_activation_lock);
  377. cpu_hotplug_driver_lock();
  378. if (bL_switcher_active) {
  379. cpu_hotplug_driver_unlock();
  380. mutex_unlock(&bL_switcher_activation_lock);
  381. return 0;
  382. }
  383. pr_info("big.LITTLE switcher initializing\n");
  384. ret = bL_activation_notify(BL_NOTIFY_PRE_ENABLE);
  385. if (ret)
  386. goto error;
  387. ret = bL_switcher_halve_cpus();
  388. if (ret)
  389. goto error;
  390. for_each_online_cpu(cpu) {
  391. struct bL_thread *t = &bL_threads[cpu];
  392. init_waitqueue_head(&t->wq);
  393. init_completion(&t->started);
  394. t->wanted_cluster = -1;
  395. t->task = bL_switcher_thread_create(cpu, t);
  396. }
  397. bL_switcher_active = 1;
  398. bL_activation_notify(BL_NOTIFY_POST_ENABLE);
  399. pr_info("big.LITTLE switcher initialized\n");
  400. goto out;
  401. error:
  402. pr_warn("big.LITTLE switcher initialization failed\n");
  403. bL_activation_notify(BL_NOTIFY_POST_DISABLE);
  404. out:
  405. cpu_hotplug_driver_unlock();
  406. mutex_unlock(&bL_switcher_activation_lock);
  407. return ret;
  408. }
  409. #ifdef CONFIG_SYSFS
  410. static void bL_switcher_disable(void)
  411. {
  412. unsigned int cpu, cluster;
  413. struct bL_thread *t;
  414. struct task_struct *task;
  415. mutex_lock(&bL_switcher_activation_lock);
  416. cpu_hotplug_driver_lock();
  417. if (!bL_switcher_active)
  418. goto out;
  419. if (bL_activation_notify(BL_NOTIFY_PRE_DISABLE) != 0) {
  420. bL_activation_notify(BL_NOTIFY_POST_ENABLE);
  421. goto out;
  422. }
  423. bL_switcher_active = 0;
  424. /*
  425. * To deactivate the switcher, we must shut down the switcher
  426. * threads to prevent any other requests from being accepted.
  427. * Then, if the final cluster for given logical CPU is not the
  428. * same as the original one, we'll recreate a switcher thread
  429. * just for the purpose of switching the CPU back without any
  430. * possibility for interference from external requests.
  431. */
  432. for_each_online_cpu(cpu) {
  433. t = &bL_threads[cpu];
  434. task = t->task;
  435. t->task = NULL;
  436. if (!task || IS_ERR(task))
  437. continue;
  438. kthread_stop(task);
  439. /* no more switch may happen on this CPU at this point */
  440. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 1);
  441. if (cluster == bL_switcher_cpu_original_cluster[cpu])
  442. continue;
  443. init_completion(&t->started);
  444. t->wanted_cluster = bL_switcher_cpu_original_cluster[cpu];
  445. task = bL_switcher_thread_create(cpu, t);
  446. if (!IS_ERR(task)) {
  447. wait_for_completion(&t->started);
  448. kthread_stop(task);
  449. cluster = MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 1);
  450. if (cluster == bL_switcher_cpu_original_cluster[cpu])
  451. continue;
  452. }
  453. /* If execution gets here, we're in trouble. */
  454. pr_crit("%s: unable to restore original cluster for CPU %d\n",
  455. __func__, cpu);
  456. pr_crit("%s: CPU %d can't be restored\n",
  457. __func__, bL_switcher_cpu_pairing[cpu]);
  458. cpumask_clear_cpu(bL_switcher_cpu_pairing[cpu],
  459. &bL_switcher_removed_logical_cpus);
  460. }
  461. bL_switcher_restore_cpus();
  462. bL_activation_notify(BL_NOTIFY_POST_DISABLE);
  463. out:
  464. cpu_hotplug_driver_unlock();
  465. mutex_unlock(&bL_switcher_activation_lock);
  466. }
  467. static ssize_t bL_switcher_active_show(struct kobject *kobj,
  468. struct kobj_attribute *attr, char *buf)
  469. {
  470. return sprintf(buf, "%u\n", bL_switcher_active);
  471. }
  472. static ssize_t bL_switcher_active_store(struct kobject *kobj,
  473. struct kobj_attribute *attr, const char *buf, size_t count)
  474. {
  475. int ret;
  476. switch (buf[0]) {
  477. case '0':
  478. bL_switcher_disable();
  479. ret = 0;
  480. break;
  481. case '1':
  482. ret = bL_switcher_enable();
  483. break;
  484. default:
  485. ret = -EINVAL;
  486. }
  487. return (ret >= 0) ? count : ret;
  488. }
  489. static struct kobj_attribute bL_switcher_active_attr =
  490. __ATTR(active, 0644, bL_switcher_active_show, bL_switcher_active_store);
  491. static struct attribute *bL_switcher_attrs[] = {
  492. &bL_switcher_active_attr.attr,
  493. NULL,
  494. };
  495. static struct attribute_group bL_switcher_attr_group = {
  496. .attrs = bL_switcher_attrs,
  497. };
  498. static struct kobject *bL_switcher_kobj;
  499. static int __init bL_switcher_sysfs_init(void)
  500. {
  501. int ret;
  502. bL_switcher_kobj = kobject_create_and_add("bL_switcher", kernel_kobj);
  503. if (!bL_switcher_kobj)
  504. return -ENOMEM;
  505. ret = sysfs_create_group(bL_switcher_kobj, &bL_switcher_attr_group);
  506. if (ret)
  507. kobject_put(bL_switcher_kobj);
  508. return ret;
  509. }
  510. #endif /* CONFIG_SYSFS */
  511. bool bL_switcher_get_enabled(void)
  512. {
  513. mutex_lock(&bL_switcher_activation_lock);
  514. return bL_switcher_active;
  515. }
  516. EXPORT_SYMBOL_GPL(bL_switcher_get_enabled);
  517. void bL_switcher_put_enabled(void)
  518. {
  519. mutex_unlock(&bL_switcher_activation_lock);
  520. }
  521. EXPORT_SYMBOL_GPL(bL_switcher_put_enabled);
  522. /*
  523. * Veto any CPU hotplug operation on those CPUs we've removed
  524. * while the switcher is active.
  525. * We're just not ready to deal with that given the trickery involved.
  526. */
  527. static int bL_switcher_hotplug_callback(struct notifier_block *nfb,
  528. unsigned long action, void *hcpu)
  529. {
  530. if (bL_switcher_active) {
  531. int pairing = bL_switcher_cpu_pairing[(unsigned long)hcpu];
  532. switch (action & 0xf) {
  533. case CPU_UP_PREPARE:
  534. case CPU_DOWN_PREPARE:
  535. if (pairing == -1)
  536. return NOTIFY_BAD;
  537. }
  538. }
  539. return NOTIFY_DONE;
  540. }
  541. static bool no_bL_switcher;
  542. core_param(no_bL_switcher, no_bL_switcher, bool, 0644);
  543. static int __init bL_switcher_init(void)
  544. {
  545. int ret;
  546. if (MAX_NR_CLUSTERS != 2) {
  547. pr_err("%s: only dual cluster systems are supported\n", __func__);
  548. return -EINVAL;
  549. }
  550. cpu_notifier(bL_switcher_hotplug_callback, 0);
  551. if (!no_bL_switcher) {
  552. ret = bL_switcher_enable();
  553. if (ret)
  554. return ret;
  555. }
  556. #ifdef CONFIG_SYSFS
  557. ret = bL_switcher_sysfs_init();
  558. if (ret)
  559. pr_err("%s: unable to create sysfs entry\n", __func__);
  560. #endif
  561. return 0;
  562. }
  563. late_initcall(bL_switcher_init);