pastebin - collaborative debugging tool
eckelmann.kpaste.net RSS


Quantron: Set CC irq thread scheduler parameters
Posted by Anonymous on Tue 22nd Oct 2019 13:45
raw | new post
modification of post by Anonymous (view diff)

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