pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Quantron: Set CC irq thread scheduler parameters
Posted by Anonymous on Tue 22nd Oct 2019 13:29
raw | new post
view followups (newest first): Quantron: Set CC irq thread scheduler parameters by Anonymous

  1. diff --git a/ptxdist/local_src/ecu01-comp-cap/main.c b/ptxdist/local_src/ecu01-comp-cap/main.c
  2. index 1fe9651..785aa36 100644
  3. --- a/ptxdist/local_src/ecu01-comp-cap/main.c
  4. +++ b/ptxdist/local_src/ecu01-comp-cap/main.c
  5. @@ -47,7 +47,11 @@
  6.  #include <linux/seq_file.h>
  7.  #include <linux/cdev.h>
  8.  #include <linux/spinlock.h>
  9. -
  10. +#include <linux/irq.h>
  11. +#include <linux/irqdesc.h>
  12. +#include <linux/interrupt.h>
  13. +#include <linux/sched.h>
  14. +#include <linux/sched/rt.h>
  15.  //#include <asm/system.h>         /* cli(), *_flags */
  16.  #include <asm/uaccess.h>        /* copy_*_user */
  17.  
  18. @@ -177,6 +181,79 @@ int comp_cap_release(struct inode *inode, struct file *filp)
  19.     return 0;
  20.  }
  21.  
  22. +static
  23. +struct task_struct *irq_desc_to_irq_thread_task_struct(struct irq_desc *irq_desc)
  24. +{
  25. +       if (irq_desc && irq_desc->action)
  26. +       {
  27. +               /*
  28. +                * Note: |irq_desc->action| can be chained if the irq
  29. +                * is a shared one. Maybe we should place a fatal assert
  30. +                * for that case since we do not handle this here.
  31. +                */
  32. +               return irq_desc->action->thread;
  33. +       }
  34. +
  35. +       return NULL;
  36. +}
  37. +
  38. +#define ECU01_CC_IRQ_THREAD_RTPRIO (MAX_USER_RT_PRIO-1)
  39. +
  40. +/*
  41. + * set scheduler paramters of the compare capture interrupt threads
  42. + *
  43. + * Note: Realtime priorities of the compare capture interrupt
  44. + * threads can be monitored with
  45. + * $ ps -e -o s,tid,pid,cls,pri,rtprio,comm,time | egrep 'irq/.+CC' #
  46. + *
  47. + * ToDo: Failure to set the parameters should be fatal for the
  48. + * |open()| syscall which calls this function!
  49. + */
  50. +static
  51. +void set_cc_irq_thread_scheduler_parameters(struct comp_cap_dev_priv *priv_dev)
  52. +{
  53. +       struct irq_desc *irq_desc;
  54. +       bool set_sched_success = false;
  55. +       struct task_struct *ts;
  56. +       struct sched_param param;
  57. +       (void)memset(&param, 0, sizeof(param));
  58. +       param.sched_priority = ECU01_CC_IRQ_THREAD_RTPRIO;
  59. +
  60. +       irq_desc = irq_to_desc(priv_dev->IRQ);
  61. +       if (!irq_desc)
  62. +       {
  63. +               /* This can fail with certain kernel CONFIG_* settings */
  64. +               (void)printk(KERN_EMERG "%s:%d: %s\n",
  65. +                       __func__, __LINE__, "irq_to_desc() failed.");
  66. +               return;
  67. +       }
  68. +
  69. +       ts = irq_desc_to_irq_thread_task_struct(irq_desc);
  70. +       if (ts)
  71. +       {
  72. +               if (sched_setscheduler(ts, SCHED_FIFO, &param) == 0)
  73. +                       set_sched_success = true;
  74. +       }
  75. +
  76. +       /*
  77. +        * Be very verbose&loud about setting the scheduler class
  78. +        * and priority, since the application will not work correctly
  79. +        * if we fail to do this.
  80. +        *
  81. +        * ToDo: Propagate an error to the caller, so that a device
  82. +        * |open()| FAILS.
  83. +        */
  84. +       (void)printk(KERN_EMERG "ecu01-compcap: "
  85. +               "irq=%ld/%ld, %s interrupt thread pid=%ld to '%s'/rtprio=%ld\n",
  86. +               (long)irq_desc->irq_data.irq,
  87. +               (long)priv_dev->IRQ,
  88. +               (set_sched_success?"changed":"failed to change"),
  89. +               (long)(ts?ts->pid:-1),
  90. +               "SCHED_FIFO",
  91. +               (long)param.sched_priority);
  92. +}
  93. +
  94. +
  95.  int start_comp_cap( struct comp_cap_dev *dev, int enable )
  96.  {
  97.     int res = -1;
  98. @@ -188,6 +265,8 @@ int start_comp_cap( struct comp_cap_dev *dev, int enable )
  99.  
  100.     res = request_irq(priv_dev->IRQ, cc_isr, IRQF_DISABLED, dev->NAME , priv_dev );
  101.  
  102. +   set_cc_irq_thread_scheduler_parameters(priv_dev);
  103. +
  104.     cc_restart(priv_dev);
  105.  
  106.     priv_dev->clk = clk_get_sys( priv_dev->CLK_PROVIDER, priv_dev->CLK_PARENT);

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}





All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at