You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/01 15:39:01 UTC

[GitHub] [incubator-nuttx] hartmannathan commented on a change in pull request #4035: work_queue: schedule the work queue using the timer mechanism

hartmannathan commented on a change in pull request #4035:
URL: https://github.com/apache/incubator-nuttx/pull/4035#discussion_r662398941



##########
File path: sched/wqueue/kwork_thread.c
##########
@@ -0,0 +1,297 @@
+/****************************************************************************
+ * sched/wqueue/kwork_thread.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <unistd.h>
+#include <sched.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <assert.h>
+#include <queue.h>
+#include <debug.h>
+
+#include <nuttx/wqueue.h>
+#include <nuttx/kthread.h>
+#include <nuttx/semaphore.h>
+
+#include "wqueue/wqueue.h"
+
+#if defined(CONFIG_SCHED_WORKQUEUE)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#if defined(CONFIG_SCHED_CRITMONITOR_MAXTIME_WQUEUE) && CONFIG_SCHED_CRITMONITOR_MAXTIME_WQUEUE > 0
+#  define CALL_WORKER(worker, arg) \
+     do \
+       { \
+         uint32_t start; \
+         uint32_t elapsed; \
+         start = up_critmon_gettime(); \
+         worker(arg); \
+         elapsed = up_critmon_gettime() - start; \
+         if (elapsed > CONFIG_SCHED_CRITMONITOR_MAXTIME_WQUEUE) \
+           { \
+             serr("WORKER %p execute too long %"PRIu32"\n", \
+                   worker, elapsed); \
+           } \
+       } \
+     while (0)
+#else
+#  define CALL_WORKER(worker, arg) worker(arg)
+#endif
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#if defined(CONFIG_SCHED_HPWORK)
+/* The state of the kernel mode, high priority work queue(s). */
+
+struct hp_wqueue_s g_hpwork;
+#endif /* CONFIG_SCHED_HPWORK */
+
+#if defined(CONFIG_SCHED_LPWORK)
+/* The state of the kernel mode, low priority work queue(s). */
+
+struct lp_wqueue_s g_lpwork;
+#endif /* CONFIG_SCHED_LPWORK */
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: work_thread
+ *
+ * Description:
+ *   These are the worker threads that performs the actions placed on the
+ *   high priority work queue.
+ *
+ *   These, along with the lower priority worker thread(s) are the kernel
+ *   mode work queues (also build in the flat build).
+ *
+ *   All kernel mode worker threads are started by the OS during normal
+ *   bring up.  This entry point is referenced by OS internally and should
+ *   not be accessed by application logic.
+ *
+ * Input Parameters:
+ *   argc, argv (not used)
+ *
+ * Returned Value:
+ *   Does not return
+ *
+ ****************************************************************************/
+
+static int work_thread(int argc, FAR char *argv[])
+{
+  FAR struct kwork_wqueue_s *wqueue;
+  FAR struct work_s *work;
+  worker_t  worker;
+  irqstate_t flags;
+  FAR void *arg;
+
+  wqueue = (FAR struct kwork_wqueue_s *)
+           ((uintptr_t)strtoul(argv[1], NULL, 0));
+
+  flags = enter_critical_section();
+
+  /* Loop forever */
+
+  for (; ; )
+    {
+      /* Then process queued work.  work_process will not return until: (1)
+       * there is no further work in the work queue, and (2) semaphore is
+       * posted.
+       */
+
+      nxsem_wait_uninterruptible(&wqueue->sem);
+
+      /* And check each entry in the work queue.  Since we have disabled
+       * interrupts we know:  (1) we will not be suspended unless we do
+       * so ourselves, and (2) there will be no changes to the work queue
+       */
+
+      /* Remove the ready-to-execute work from the list */
+
+      work = (FAR struct work_s *)sq_remfirst(&wqueue->q);
+      if (work && work->worker)
+        {
+          /* Extract the work description from the entry (in case the work
+           * instance by the re-used after it has been de-queued).

Review comment:
       This comment doesn't quite make sense. Perhaps you mean something like:
   
   "Extract the work description from the entry (in case the work instance will be re-used after it has been de-queued)."




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org