qman_test_stash.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /* Copyright 2009 - 2016 Freescale Semiconductor, Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. * ALTERNATIVELY, this software may be distributed under the terms of the
  15. * GNU General Public License ("GPL") as published by the Free Software
  16. * Foundation, either version 2 of that License or (at your option) any
  17. * later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  20. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  23. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #include "qman_test.h"
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. /*
  34. * Algorithm:
  35. *
  36. * Each cpu will have HP_PER_CPU "handlers" set up, each of which incorporates
  37. * an rx/tx pair of FQ objects (both of which are stashed on dequeue). The
  38. * organisation of FQIDs is such that the HP_PER_CPU*NUM_CPUS handlers will
  39. * shuttle a "hot potato" frame around them such that every forwarding action
  40. * moves it from one cpu to another. (The use of more than one handler per cpu
  41. * is to allow enough handlers/FQs to truly test the significance of caching -
  42. * ie. when cache-expiries are occurring.)
  43. *
  44. * The "hot potato" frame content will be HP_NUM_WORDS*4 bytes in size, and the
  45. * first and last words of the frame data will undergo a transformation step on
  46. * each forwarding action. To achieve this, each handler will be assigned a
  47. * 32-bit "mixer", that is produced using a 32-bit LFSR. When a frame is
  48. * received by a handler, the mixer of the expected sender is XOR'd into all
  49. * words of the entire frame, which is then validated against the original
  50. * values. Then, before forwarding, the entire frame is XOR'd with the mixer of
  51. * the current handler. Apart from validating that the frame is taking the
  52. * expected path, this also provides some quasi-realistic overheads to each
  53. * forwarding action - dereferencing *all* the frame data, computation, and
  54. * conditional branching. There is a "special" handler designated to act as the
  55. * instigator of the test by creating an enqueuing the "hot potato" frame, and
  56. * to determine when the test has completed by counting HP_LOOPS iterations.
  57. *
  58. * Init phases:
  59. *
  60. * 1. prepare each cpu's 'hp_cpu' struct using on_each_cpu(,,1) and link them
  61. * into 'hp_cpu_list'. Specifically, set processor_id, allocate HP_PER_CPU
  62. * handlers and link-list them (but do no other handler setup).
  63. *
  64. * 2. scan over 'hp_cpu_list' HP_PER_CPU times, the first time sets each
  65. * hp_cpu's 'iterator' to point to its first handler. With each loop,
  66. * allocate rx/tx FQIDs and mixer values to the hp_cpu's iterator handler
  67. * and advance the iterator for the next loop. This includes a final fixup,
  68. * which connects the last handler to the first (and which is why phase 2
  69. * and 3 are separate).
  70. *
  71. * 3. scan over 'hp_cpu_list' HP_PER_CPU times, the first time sets each
  72. * hp_cpu's 'iterator' to point to its first handler. With each loop,
  73. * initialise FQ objects and advance the iterator for the next loop.
  74. * Moreover, do this initialisation on the cpu it applies to so that Rx FQ
  75. * initialisation targets the correct cpu.
  76. */
  77. /*
  78. * helper to run something on all cpus (can't use on_each_cpu(), as that invokes
  79. * the fn from irq context, which is too restrictive).
  80. */
  81. struct bstrap {
  82. int (*fn)(void);
  83. atomic_t started;
  84. };
  85. static int bstrap_fn(void *bs)
  86. {
  87. struct bstrap *bstrap = bs;
  88. int err;
  89. atomic_inc(&bstrap->started);
  90. err = bstrap->fn();
  91. if (err)
  92. return err;
  93. while (!kthread_should_stop())
  94. msleep(20);
  95. return 0;
  96. }
  97. static int on_all_cpus(int (*fn)(void))
  98. {
  99. int cpu;
  100. for_each_cpu(cpu, cpu_online_mask) {
  101. struct bstrap bstrap = {
  102. .fn = fn,
  103. .started = ATOMIC_INIT(0)
  104. };
  105. struct task_struct *k = kthread_create(bstrap_fn, &bstrap,
  106. "hotpotato%d", cpu);
  107. int ret;
  108. if (IS_ERR(k))
  109. return -ENOMEM;
  110. kthread_bind(k, cpu);
  111. wake_up_process(k);
  112. /*
  113. * If we call kthread_stop() before the "wake up" has had an
  114. * effect, then the thread may exit with -EINTR without ever
  115. * running the function. So poll until it's started before
  116. * requesting it to stop.
  117. */
  118. while (!atomic_read(&bstrap.started))
  119. msleep(20);
  120. ret = kthread_stop(k);
  121. if (ret)
  122. return ret;
  123. }
  124. return 0;
  125. }
  126. struct hp_handler {
  127. /* The following data is stashed when 'rx' is dequeued; */
  128. /* -------------- */
  129. /* The Rx FQ, dequeues of which will stash the entire hp_handler */
  130. struct qman_fq rx;
  131. /* The Tx FQ we should forward to */
  132. struct qman_fq tx;
  133. /* The value we XOR post-dequeue, prior to validating */
  134. u32 rx_mixer;
  135. /* The value we XOR pre-enqueue, after validating */
  136. u32 tx_mixer;
  137. /* what the hotpotato address should be on dequeue */
  138. dma_addr_t addr;
  139. u32 *frame_ptr;
  140. /* The following data isn't (necessarily) stashed on dequeue; */
  141. /* -------------- */
  142. u32 fqid_rx, fqid_tx;
  143. /* list node for linking us into 'hp_cpu' */
  144. struct list_head node;
  145. /* Just to check ... */
  146. unsigned int processor_id;
  147. } ____cacheline_aligned;
  148. struct hp_cpu {
  149. /* identify the cpu we run on; */
  150. unsigned int processor_id;
  151. /* root node for the per-cpu list of handlers */
  152. struct list_head handlers;
  153. /* list node for linking us into 'hp_cpu_list' */
  154. struct list_head node;
  155. /*
  156. * when repeatedly scanning 'hp_list', each time linking the n'th
  157. * handlers together, this is used as per-cpu iterator state
  158. */
  159. struct hp_handler *iterator;
  160. };
  161. /* Each cpu has one of these */
  162. static DEFINE_PER_CPU(struct hp_cpu, hp_cpus);
  163. /* links together the hp_cpu structs, in first-come first-serve order. */
  164. static LIST_HEAD(hp_cpu_list);
  165. static spinlock_t hp_lock = __SPIN_LOCK_UNLOCKED(hp_lock);
  166. static unsigned int hp_cpu_list_length;
  167. /* the "special" handler, that starts and terminates the test. */
  168. static struct hp_handler *special_handler;
  169. static int loop_counter;
  170. /* handlers are allocated out of this, so they're properly aligned. */
  171. static struct kmem_cache *hp_handler_slab;
  172. /* this is the frame data */
  173. static void *__frame_ptr;
  174. static u32 *frame_ptr;
  175. static dma_addr_t frame_dma;
  176. /* the main function waits on this */
  177. static DECLARE_WAIT_QUEUE_HEAD(queue);
  178. #define HP_PER_CPU 2
  179. #define HP_LOOPS 8
  180. /* 80 bytes, like a small ethernet frame, and bleeds into a second cacheline */
  181. #define HP_NUM_WORDS 80
  182. /* First word of the LFSR-based frame data */
  183. #define HP_FIRST_WORD 0xabbaf00d
  184. static inline u32 do_lfsr(u32 prev)
  185. {
  186. return (prev >> 1) ^ (-(prev & 1u) & 0xd0000001u);
  187. }
  188. static int allocate_frame_data(void)
  189. {
  190. u32 lfsr = HP_FIRST_WORD;
  191. int loop;
  192. struct platform_device *pdev = platform_device_alloc("foobar", -1);
  193. if (!pdev) {
  194. pr_crit("platform_device_alloc() failed");
  195. return -EIO;
  196. }
  197. if (platform_device_add(pdev)) {
  198. pr_crit("platform_device_add() failed");
  199. return -EIO;
  200. }
  201. __frame_ptr = kmalloc(4 * HP_NUM_WORDS, GFP_KERNEL);
  202. if (!__frame_ptr)
  203. return -ENOMEM;
  204. frame_ptr = PTR_ALIGN(__frame_ptr, 64);
  205. for (loop = 0; loop < HP_NUM_WORDS; loop++) {
  206. frame_ptr[loop] = lfsr;
  207. lfsr = do_lfsr(lfsr);
  208. }
  209. frame_dma = dma_map_single(&pdev->dev, frame_ptr, 4 * HP_NUM_WORDS,
  210. DMA_BIDIRECTIONAL);
  211. platform_device_del(pdev);
  212. platform_device_put(pdev);
  213. return 0;
  214. }
  215. static void deallocate_frame_data(void)
  216. {
  217. kfree(__frame_ptr);
  218. }
  219. static inline int process_frame_data(struct hp_handler *handler,
  220. const struct qm_fd *fd)
  221. {
  222. u32 *p = handler->frame_ptr;
  223. u32 lfsr = HP_FIRST_WORD;
  224. int loop;
  225. if (qm_fd_addr_get64(fd) != handler->addr) {
  226. pr_crit("bad frame address");
  227. return -EIO;
  228. }
  229. for (loop = 0; loop < HP_NUM_WORDS; loop++, p++) {
  230. *p ^= handler->rx_mixer;
  231. if (*p != lfsr) {
  232. pr_crit("corrupt frame data");
  233. return -EIO;
  234. }
  235. *p ^= handler->tx_mixer;
  236. lfsr = do_lfsr(lfsr);
  237. }
  238. return 0;
  239. }
  240. static enum qman_cb_dqrr_result normal_dqrr(struct qman_portal *portal,
  241. struct qman_fq *fq,
  242. const struct qm_dqrr_entry *dqrr)
  243. {
  244. struct hp_handler *handler = (struct hp_handler *)fq;
  245. if (process_frame_data(handler, &dqrr->fd)) {
  246. WARN_ON(1);
  247. goto skip;
  248. }
  249. if (qman_enqueue(&handler->tx, &dqrr->fd)) {
  250. pr_crit("qman_enqueue() failed");
  251. WARN_ON(1);
  252. }
  253. skip:
  254. return qman_cb_dqrr_consume;
  255. }
  256. static enum qman_cb_dqrr_result special_dqrr(struct qman_portal *portal,
  257. struct qman_fq *fq,
  258. const struct qm_dqrr_entry *dqrr)
  259. {
  260. struct hp_handler *handler = (struct hp_handler *)fq;
  261. process_frame_data(handler, &dqrr->fd);
  262. if (++loop_counter < HP_LOOPS) {
  263. if (qman_enqueue(&handler->tx, &dqrr->fd)) {
  264. pr_crit("qman_enqueue() failed");
  265. WARN_ON(1);
  266. goto skip;
  267. }
  268. } else {
  269. pr_info("Received final (%dth) frame\n", loop_counter);
  270. wake_up(&queue);
  271. }
  272. skip:
  273. return qman_cb_dqrr_consume;
  274. }
  275. static int create_per_cpu_handlers(void)
  276. {
  277. struct hp_handler *handler;
  278. int loop;
  279. struct hp_cpu *hp_cpu = this_cpu_ptr(&hp_cpus);
  280. hp_cpu->processor_id = smp_processor_id();
  281. spin_lock(&hp_lock);
  282. list_add_tail(&hp_cpu->node, &hp_cpu_list);
  283. hp_cpu_list_length++;
  284. spin_unlock(&hp_lock);
  285. INIT_LIST_HEAD(&hp_cpu->handlers);
  286. for (loop = 0; loop < HP_PER_CPU; loop++) {
  287. handler = kmem_cache_alloc(hp_handler_slab, GFP_KERNEL);
  288. if (!handler) {
  289. pr_crit("kmem_cache_alloc() failed");
  290. WARN_ON(1);
  291. return -EIO;
  292. }
  293. handler->processor_id = hp_cpu->processor_id;
  294. handler->addr = frame_dma;
  295. handler->frame_ptr = frame_ptr;
  296. list_add_tail(&handler->node, &hp_cpu->handlers);
  297. }
  298. return 0;
  299. }
  300. static int destroy_per_cpu_handlers(void)
  301. {
  302. struct list_head *loop, *tmp;
  303. struct hp_cpu *hp_cpu = this_cpu_ptr(&hp_cpus);
  304. spin_lock(&hp_lock);
  305. list_del(&hp_cpu->node);
  306. spin_unlock(&hp_lock);
  307. list_for_each_safe(loop, tmp, &hp_cpu->handlers) {
  308. u32 flags = 0;
  309. struct hp_handler *handler = list_entry(loop, struct hp_handler,
  310. node);
  311. if (qman_retire_fq(&handler->rx, &flags) ||
  312. (flags & QMAN_FQ_STATE_BLOCKOOS)) {
  313. pr_crit("qman_retire_fq(rx) failed, flags: %x", flags);
  314. WARN_ON(1);
  315. return -EIO;
  316. }
  317. if (qman_oos_fq(&handler->rx)) {
  318. pr_crit("qman_oos_fq(rx) failed");
  319. WARN_ON(1);
  320. return -EIO;
  321. }
  322. qman_destroy_fq(&handler->rx);
  323. qman_destroy_fq(&handler->tx);
  324. qman_release_fqid(handler->fqid_rx);
  325. list_del(&handler->node);
  326. kmem_cache_free(hp_handler_slab, handler);
  327. }
  328. return 0;
  329. }
  330. static inline u8 num_cachelines(u32 offset)
  331. {
  332. u8 res = (offset + (L1_CACHE_BYTES - 1))
  333. / (L1_CACHE_BYTES);
  334. if (res > 3)
  335. return 3;
  336. return res;
  337. }
  338. #define STASH_DATA_CL \
  339. num_cachelines(HP_NUM_WORDS * 4)
  340. #define STASH_CTX_CL \
  341. num_cachelines(offsetof(struct hp_handler, fqid_rx))
  342. static int init_handler(void *h)
  343. {
  344. struct qm_mcc_initfq opts;
  345. struct hp_handler *handler = h;
  346. int err;
  347. if (handler->processor_id != smp_processor_id()) {
  348. err = -EIO;
  349. goto failed;
  350. }
  351. /* Set up rx */
  352. memset(&handler->rx, 0, sizeof(handler->rx));
  353. if (handler == special_handler)
  354. handler->rx.cb.dqrr = special_dqrr;
  355. else
  356. handler->rx.cb.dqrr = normal_dqrr;
  357. err = qman_create_fq(handler->fqid_rx, 0, &handler->rx);
  358. if (err) {
  359. pr_crit("qman_create_fq(rx) failed");
  360. goto failed;
  361. }
  362. memset(&opts, 0, sizeof(opts));
  363. opts.we_mask = QM_INITFQ_WE_FQCTRL | QM_INITFQ_WE_CONTEXTA;
  364. opts.fqd.fq_ctrl = QM_FQCTRL_CTXASTASHING;
  365. qm_fqd_set_stashing(&opts.fqd, 0, STASH_DATA_CL, STASH_CTX_CL);
  366. err = qman_init_fq(&handler->rx, QMAN_INITFQ_FLAG_SCHED |
  367. QMAN_INITFQ_FLAG_LOCAL, &opts);
  368. if (err) {
  369. pr_crit("qman_init_fq(rx) failed");
  370. goto failed;
  371. }
  372. /* Set up tx */
  373. memset(&handler->tx, 0, sizeof(handler->tx));
  374. err = qman_create_fq(handler->fqid_tx, QMAN_FQ_FLAG_NO_MODIFY,
  375. &handler->tx);
  376. if (err) {
  377. pr_crit("qman_create_fq(tx) failed");
  378. goto failed;
  379. }
  380. return 0;
  381. failed:
  382. return err;
  383. }
  384. static void init_handler_cb(void *h)
  385. {
  386. if (init_handler(h))
  387. WARN_ON(1);
  388. }
  389. static int init_phase2(void)
  390. {
  391. int loop;
  392. u32 fqid = 0;
  393. u32 lfsr = 0xdeadbeef;
  394. struct hp_cpu *hp_cpu;
  395. struct hp_handler *handler;
  396. for (loop = 0; loop < HP_PER_CPU; loop++) {
  397. list_for_each_entry(hp_cpu, &hp_cpu_list, node) {
  398. int err;
  399. if (!loop)
  400. hp_cpu->iterator = list_first_entry(
  401. &hp_cpu->handlers,
  402. struct hp_handler, node);
  403. else
  404. hp_cpu->iterator = list_entry(
  405. hp_cpu->iterator->node.next,
  406. struct hp_handler, node);
  407. /* Rx FQID is the previous handler's Tx FQID */
  408. hp_cpu->iterator->fqid_rx = fqid;
  409. /* Allocate new FQID for Tx */
  410. err = qman_alloc_fqid(&fqid);
  411. if (err) {
  412. pr_crit("qman_alloc_fqid() failed");
  413. return err;
  414. }
  415. hp_cpu->iterator->fqid_tx = fqid;
  416. /* Rx mixer is the previous handler's Tx mixer */
  417. hp_cpu->iterator->rx_mixer = lfsr;
  418. /* Get new mixer for Tx */
  419. lfsr = do_lfsr(lfsr);
  420. hp_cpu->iterator->tx_mixer = lfsr;
  421. }
  422. }
  423. /* Fix up the first handler (fqid_rx==0, rx_mixer=0xdeadbeef) */
  424. hp_cpu = list_first_entry(&hp_cpu_list, struct hp_cpu, node);
  425. handler = list_first_entry(&hp_cpu->handlers, struct hp_handler, node);
  426. if (handler->fqid_rx != 0 || handler->rx_mixer != 0xdeadbeef)
  427. return 1;
  428. handler->fqid_rx = fqid;
  429. handler->rx_mixer = lfsr;
  430. /* and tag it as our "special" handler */
  431. special_handler = handler;
  432. return 0;
  433. }
  434. static int init_phase3(void)
  435. {
  436. int loop, err;
  437. struct hp_cpu *hp_cpu;
  438. for (loop = 0; loop < HP_PER_CPU; loop++) {
  439. list_for_each_entry(hp_cpu, &hp_cpu_list, node) {
  440. if (!loop)
  441. hp_cpu->iterator = list_first_entry(
  442. &hp_cpu->handlers,
  443. struct hp_handler, node);
  444. else
  445. hp_cpu->iterator = list_entry(
  446. hp_cpu->iterator->node.next,
  447. struct hp_handler, node);
  448. preempt_disable();
  449. if (hp_cpu->processor_id == smp_processor_id()) {
  450. err = init_handler(hp_cpu->iterator);
  451. if (err)
  452. return err;
  453. } else {
  454. smp_call_function_single(hp_cpu->processor_id,
  455. init_handler_cb, hp_cpu->iterator, 1);
  456. }
  457. preempt_enable();
  458. }
  459. }
  460. return 0;
  461. }
  462. static int send_first_frame(void *ignore)
  463. {
  464. u32 *p = special_handler->frame_ptr;
  465. u32 lfsr = HP_FIRST_WORD;
  466. int loop, err;
  467. struct qm_fd fd;
  468. if (special_handler->processor_id != smp_processor_id()) {
  469. err = -EIO;
  470. goto failed;
  471. }
  472. memset(&fd, 0, sizeof(fd));
  473. qm_fd_addr_set64(&fd, special_handler->addr);
  474. qm_fd_set_contig_big(&fd, HP_NUM_WORDS * 4);
  475. for (loop = 0; loop < HP_NUM_WORDS; loop++, p++) {
  476. if (*p != lfsr) {
  477. err = -EIO;
  478. pr_crit("corrupt frame data");
  479. goto failed;
  480. }
  481. *p ^= special_handler->tx_mixer;
  482. lfsr = do_lfsr(lfsr);
  483. }
  484. pr_info("Sending first frame\n");
  485. err = qman_enqueue(&special_handler->tx, &fd);
  486. if (err) {
  487. pr_crit("qman_enqueue() failed");
  488. goto failed;
  489. }
  490. return 0;
  491. failed:
  492. return err;
  493. }
  494. static void send_first_frame_cb(void *ignore)
  495. {
  496. if (send_first_frame(NULL))
  497. WARN_ON(1);
  498. }
  499. int qman_test_stash(void)
  500. {
  501. int err;
  502. if (cpumask_weight(cpu_online_mask) < 2) {
  503. pr_info("%s(): skip - only 1 CPU\n", __func__);
  504. return 0;
  505. }
  506. pr_info("%s(): Starting\n", __func__);
  507. hp_cpu_list_length = 0;
  508. loop_counter = 0;
  509. hp_handler_slab = kmem_cache_create("hp_handler_slab",
  510. sizeof(struct hp_handler), L1_CACHE_BYTES,
  511. SLAB_HWCACHE_ALIGN, NULL);
  512. if (!hp_handler_slab) {
  513. err = -EIO;
  514. pr_crit("kmem_cache_create() failed");
  515. goto failed;
  516. }
  517. err = allocate_frame_data();
  518. if (err)
  519. goto failed;
  520. /* Init phase 1 */
  521. pr_info("Creating %d handlers per cpu...\n", HP_PER_CPU);
  522. if (on_all_cpus(create_per_cpu_handlers)) {
  523. err = -EIO;
  524. pr_crit("on_each_cpu() failed");
  525. goto failed;
  526. }
  527. pr_info("Number of cpus: %d, total of %d handlers\n",
  528. hp_cpu_list_length, hp_cpu_list_length * HP_PER_CPU);
  529. err = init_phase2();
  530. if (err)
  531. goto failed;
  532. err = init_phase3();
  533. if (err)
  534. goto failed;
  535. preempt_disable();
  536. if (special_handler->processor_id == smp_processor_id()) {
  537. err = send_first_frame(NULL);
  538. if (err)
  539. goto failed;
  540. } else {
  541. smp_call_function_single(special_handler->processor_id,
  542. send_first_frame_cb, NULL, 1);
  543. }
  544. preempt_enable();
  545. wait_event(queue, loop_counter == HP_LOOPS);
  546. deallocate_frame_data();
  547. if (on_all_cpus(destroy_per_cpu_handlers)) {
  548. err = -EIO;
  549. pr_crit("on_each_cpu() failed");
  550. goto failed;
  551. }
  552. kmem_cache_destroy(hp_handler_slab);
  553. pr_info("%s(): Finished\n", __func__);
  554. return 0;
  555. failed:
  556. WARN_ON(1);
  557. return err;
  558. }