cfs_wi_scheduler (void *arg)
{
struct cfs_wi_sched *sched = (cfs_wi_sched_t *)arg;
- char name[16];
-
- if (sched->ws_cptab != NULL && sched->ws_cpt >= 0) {
- snprintf(name, sizeof(name), "%s_%02d_%02d",
- sched->ws_name, sched->ws_cpt, sched->ws_nthreads);
- } else {
- snprintf(name, sizeof(name), "%s_%02d",
- sched->ws_name, sched->ws_nthreads);
- }
- cfs_daemonize(name);
cfs_block_allsigs();
/* CPT affinity scheduler? */
if (sched->ws_cptab != NULL)
- cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt);
+ if (cfs_cpt_bind(sched->ws_cptab, sched->ws_cpt) != 0)
+ CWARN("Failed to bind %s on CPT %d\n",
+ sched->ws_name, sched->ws_cpt);
spin_lock(&cfs_wi_data.wi_glock);
continue;
}
- cfs_wi_sched_unlock(sched);
- cfs_wait_event_interruptible_exclusive(sched->ws_waitq,
- !cfs_wi_sched_cansleep(sched), rc);
- cfs_wi_sched_lock(sched);
+ cfs_wi_sched_unlock(sched);
+ rc = wait_event_interruptible_exclusive(sched->ws_waitq,
+ !cfs_wi_sched_cansleep(sched));
+ cfs_wi_sched_lock(sched);
}
cfs_wi_sched_unlock(sched);
void
cfs_wi_sched_destroy(struct cfs_wi_sched *sched)
{
- int i;
-
LASSERT(cfs_wi_data.wi_init);
LASSERT(!cfs_wi_data.wi_stopping);
spin_unlock(&cfs_wi_data.wi_glock);
- i = 2;
#ifdef __KERNEL__
cfs_waitq_broadcast(&sched->ws_waitq);
spin_lock(&cfs_wi_data.wi_glock);
- while (sched->ws_nthreads > 0) {
- CDEBUG(IS_PO2(++i) ? D_WARNING : D_NET,
- "waiting for %d threads of WI sched[%s] to terminate\n",
- sched->ws_nthreads, sched->ws_name);
+ {
+ int i = 2;
- spin_unlock(&cfs_wi_data.wi_glock);
- cfs_pause(cfs_time_seconds(1) / 20);
- spin_lock(&cfs_wi_data.wi_glock);
+ while (sched->ws_nthreads > 0) {
+ CDEBUG(IS_PO2(++i) ? D_WARNING : D_NET,
+ "waiting for %d threads of WI sched[%s] to "
+ "terminate\n", sched->ws_nthreads,
+ sched->ws_name);
+
+ spin_unlock(&cfs_wi_data.wi_glock);
+ cfs_pause(cfs_time_seconds(1) / 20);
+ spin_lock(&cfs_wi_data.wi_glock);
+ }
}
cfs_list_del(&sched->ws_list);
spin_unlock(&cfs_wi_data.wi_glock);
-#else
- SET_BUT_UNUSED(i);
#endif
LASSERT(sched->ws_nscheduled == 0);
int cpt, int nthrs, struct cfs_wi_sched **sched_pp)
{
struct cfs_wi_sched *sched;
- int rc;
LASSERT(cfs_wi_data.wi_init);
LASSERT(!cfs_wi_data.wi_stopping);
CFS_INIT_LIST_HEAD(&sched->ws_rerunq);
CFS_INIT_LIST_HEAD(&sched->ws_list);
- rc = 0;
#ifdef __KERNEL__
- while (nthrs > 0) {
+ for (; nthrs > 0; nthrs--) {
+ char name[16];
+ cfs_task_t *task;
+
spin_lock(&cfs_wi_data.wi_glock);
while (sched->ws_starting > 0) {
spin_unlock(&cfs_wi_data.wi_glock);
sched->ws_starting++;
spin_unlock(&cfs_wi_data.wi_glock);
- rc = cfs_create_thread(cfs_wi_scheduler, sched, 0);
- if (rc >= 0) {
- nthrs--;
- continue;
+ if (sched->ws_cptab != NULL && sched->ws_cpt >= 0) {
+ snprintf(name, sizeof(name), "%s_%02d_%02d",
+ sched->ws_name, sched->ws_cpt,
+ sched->ws_nthreads);
+ } else {
+ snprintf(name, sizeof(name), "%s_%02d",
+ sched->ws_name, sched->ws_nthreads);
}
- CERROR("Failed to create thread for WI scheduler %s: %d\n",
- name, rc);
+ task = kthread_run(cfs_wi_scheduler, sched, name);
+ if (IS_ERR(task)) {
+ int rc = PTR_ERR(task);
- spin_lock(&cfs_wi_data.wi_glock);
+ CERROR("Failed to create thread for "
+ "WI scheduler %s: %d\n", name, rc);
+
+ spin_lock(&cfs_wi_data.wi_glock);
- /* make up for cfs_wi_sched_destroy */
- cfs_list_add(&sched->ws_list, &cfs_wi_data.wi_scheds);
- sched->ws_starting--;
+ /* make up for cfs_wi_sched_destroy */
+ cfs_list_add(&sched->ws_list, &cfs_wi_data.wi_scheds);
+ sched->ws_starting--;
- spin_unlock(&cfs_wi_data.wi_glock);
+ spin_unlock(&cfs_wi_data.wi_glock);
- cfs_wi_sched_destroy(sched);
- return rc;
+ cfs_wi_sched_destroy(sched);
+ return rc;
+ }
}
-#else
- SET_BUT_UNUSED(rc);
#endif
spin_lock(&cfs_wi_data.wi_glock);
cfs_list_add(&sched->ws_list, &cfs_wi_data.wi_scheds);