int CommOS_StartIO(const char *dispatchTaskName, CommOSDispatchFunc dispatchFunc, unsigned int intervalMillis, unsigned int maxCycles, const char *aioTaskName) { int cpu; if (running) { commos_debug("%s: I/O tasks already running.\n", __func__); return 0; } if (!dispatchFunc) { commos_info("%s: a NULL Dispatch handler was passed.\n", __func__); return -1; } dispatch = dispatchFunc; if (intervalMillis == 0) intervalMillis = 4; dispatchInterval = msecs_to_jiffies(intervalMillis); if (dispatchInterval < 1) dispatchInterval = 1; if (maxCycles > DISPATCH_MAX_CYCLES) dispatchMaxCycles = DISPATCH_MAX_CYCLES; else if (maxCycles > 0) dispatchMaxCycles = maxCycles; commos_debug("%s: Interval millis %u (jif:%u).\n", __func__, intervalMillis, dispatchInterval); commos_debug("%s: Max cycles %u.\n", __func__, dispatchMaxCycles); dispatchWQ = CreateWorkqueue(dispatchTaskName); if (!dispatchWQ) { commos_info("%s: Couldn't create %s task(s).\n", __func__, dispatchTaskName); return -1; } if (aioTaskName) { aioWQ = CreateWorkqueue(aioTaskName); if (!aioWQ) { commos_info("%s: Couldn't create %s task(s).\n", __func__, aioTaskName); DestroyWorkqueue(dispatchWQ); return -1; } } else { aioWQ = NULL; } running = 1; for_each_possible_cpu(cpu) { CommOS_InitWork(&dispatchWorksNow[cpu], DispatchWrapper); CommOS_InitWork(&dispatchWorks[cpu], DispatchWrapper); } #ifdef CONFIG_HOTPLUG_CPU register_hotcpu_notifier(&CpuNotifier); #endif get_online_cpus(); for_each_online_cpu(cpu) QueueDelayedWorkOn(cpu, dispatchWQ, &dispatchWorks[cpu], dispatchInterval); put_online_cpus(); commos_info("%s: Created I/O task(s) successfully.\n", __func__); return 0; }
int CommOS_StartIO(const char *dispatchTaskName, CommOSDispatchFunc dispatchFunc, unsigned int intervalMillis, unsigned int maxCycles, const char *aioTaskName) { int rc; int cpu; if (running) { CommOS_Debug(("%s: I/O tasks already running.\n", __FUNCTION__)); return 0; } if (!dispatchFunc) { CommOS_Log(("%s: a NULL Dispatch handler was passed.\n", __FUNCTION__)); return -1; } dispatch = dispatchFunc; if (intervalMillis == 0) { intervalMillis = 4; } if ((dispatchInterval = msecs_to_jiffies(intervalMillis)) < 1) { dispatchInterval = 1; } if (maxCycles > DISPATCH_MAX_CYCLES) { dispatchMaxCycles = DISPATCH_MAX_CYCLES; } else if (maxCycles > 0) { dispatchMaxCycles = maxCycles; } CommOS_Debug(("%s: Interval millis %u (jif:%u).\n", __FUNCTION__, intervalMillis, dispatchInterval)); CommOS_Debug(("%s: Max cycles %u.\n", __FUNCTION__, dispatchMaxCycles)); numCpus = num_present_cpus(); dispatchWQ = CreateWorkqueue(dispatchTaskName); if (!dispatchWQ) { CommOS_Log(("%s: Couldn't create %s task(s).\n", __FUNCTION__, dispatchTaskName)); return -1; } if (aioTaskName) { aioWQ = CreateWorkqueue(aioTaskName); if (!aioWQ) { CommOS_Log(("%s: Couldn't create %s task(s).\n", __FUNCTION__, aioTaskName)); DestroyWorkqueue(dispatchWQ); return -1; } } else { aioWQ = NULL; } running = 1; for (cpu = 0; cpu < numCpus; cpu++) { CommOS_InitWork(&dispatchWorksNow[cpu], DispatchWrapper); CommOS_InitWork(&dispatchWorks[cpu], DispatchWrapper); rc = QueueDelayedWorkOn(cpu, dispatchWQ, &dispatchWorks[cpu], dispatchInterval); if (rc != 0) { CommOS_StopIO(); return -1; } } CommOS_Log(("%s: Created I/O task(s) successfully.\n", __FUNCTION__)); return 0; }
int CommOS_StartIO(const char *dispatchTaskName, // IN CommOSDispatchFunc dispatchFunc, // IN unsigned int intervalMillis, // IN unsigned int maxCycles, // IN const char *aioTaskName) // IN { int cpu; if (running) { CommOS_Debug(("%s: I/O tasks already running.\n", __FUNCTION__)); return 0; } /* * OK, let's test the handler against NULL. Though, the whole concept * of checking for NULL pointers, outside cases where NULL is meaningful * to the implementation, is relatively useless: garbage, random pointers * rarely happen to be all-zeros. */ if (!dispatchFunc) { CommOS_Log(("%s: a NULL Dispatch handler was passed.\n", __FUNCTION__)); return -1; } dispatch = dispatchFunc; if (intervalMillis == 0) { intervalMillis = 4; } if ((dispatchInterval = msecs_to_jiffies(intervalMillis)) < 1) { dispatchInterval = 1; } if (maxCycles > DISPATCH_MAX_CYCLES) { dispatchMaxCycles = DISPATCH_MAX_CYCLES; } else if (maxCycles > 0) { dispatchMaxCycles = maxCycles; } CommOS_Debug(("%s: Interval millis %u (jif:%u).\n", __FUNCTION__, intervalMillis, dispatchInterval)); CommOS_Debug(("%s: Max cycles %u.\n", __FUNCTION__, dispatchMaxCycles)); dispatchWQ = CreateWorkqueue(dispatchTaskName); if (!dispatchWQ) { CommOS_Log(("%s: Couldn't create %s task(s).\n", __FUNCTION__, dispatchTaskName)); return -1; } if (aioTaskName) { aioWQ = CreateWorkqueue(aioTaskName); if (!aioWQ) { CommOS_Log(("%s: Couldn't create %s task(s).\n", __FUNCTION__, aioTaskName)); DestroyWorkqueue(dispatchWQ); return -1; } } else { aioWQ = NULL; } running = 1; for_each_possible_cpu(cpu) { CommOS_InitWork(&dispatchWorksNow[cpu], DispatchWrapper); CommOS_InitWork(&dispatchWorks[cpu], DispatchWrapper); } #ifdef CONFIG_HOTPLUG_CPU register_hotcpu_notifier(&CpuNotifier); #endif get_online_cpus(); for_each_online_cpu(cpu) { QueueDelayedWorkOn(cpu, dispatchWQ, &dispatchWorks[cpu], dispatchInterval); } put_online_cpus(); CommOS_Log(("%s: Created I/O task(s) successfully.\n", __FUNCTION__)); return 0; }