Skip to content
Snippets Groups Projects
Commit a504ff46 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

more cleanup.

parent 162f50c3
No related branches found
No related tags found
No related merge requests found
...@@ -537,8 +537,6 @@ void *qsched_getdata(struct qsched *s, struct task *t) { ...@@ -537,8 +537,6 @@ void *qsched_getdata(struct qsched *s, struct task *t) {
void qsched_enqueue(struct qsched *s, struct task *t) { void qsched_enqueue(struct qsched *s, struct task *t) {
int j, qid, scores[s->nr_queues], oid;
/* If this is a virtual task, just do its unlocks and leave. */ /* If this is a virtual task, just do its unlocks and leave. */
if (t->flags & task_flag_virtual) { if (t->flags & task_flag_virtual) {
...@@ -552,23 +550,28 @@ void qsched_enqueue(struct qsched *s, struct task *t) { ...@@ -552,23 +550,28 @@ void qsched_enqueue(struct qsched *s, struct task *t) {
else { else {
/* Init the scores for each queue. */ /* Init the scores for each queue. */
for (j = 0; j < s->nr_queues; j++) scores[j] = 0; int scores[s->nr_queues];
for (int j = 0; j < s->nr_queues; j++) scores[j] = 0;
/* Loop over the locks and uses, and get their owners. */ /* Loop over the locks and uses, and get their owners. */
for (j = 0; j < t->nr_locks; j++) for (int j = 0; j < t->nr_locks; j++) {
if ((oid = s->res[t->locks[j]].owner) != qsched_owner_none) int oid = s->res[t->locks[j]].owner;
scores[oid] += 1; if (oid != qsched_owner_none) scores[oid] += 1;
for (j = 0; j < t->nr_uses; j++) }
if ((oid = s->res[t->uses[j]].owner) != qsched_owner_none) for (int j = 0; j < t->nr_uses; j++) {
scores[oid] += 1; int oid = s->res[t->uses[j]].owner;
if (oid != qsched_owner_none) scores[oid] += 1;
}
/* Find the queue with the highest score. */ /* Find the queue with the highest score. */
qid = 0; int qid = 0;
for (j = 1; j < s->nr_queues; j++) for (int j = 1; j < s->nr_queues; j++) {
if (scores[j] > scores[qid] || if (scores[j] > scores[qid] ||
(scores[j] == scores[qid] && (scores[j] == scores[qid] &&
s->queues[j].count < s->queues[qid].count)) s->queues[j].count < s->queues[qid].count)) {
qid = j; qid = j;
}
}
/* Put the unlocked task in that queue. */ /* Put the unlocked task in that queue. */
queue_put(&s->queues[qid], s, t - s->tasks); queue_put(&s->queues[qid], s, t - s->tasks);
...@@ -584,9 +587,6 @@ void qsched_enqueue(struct qsched *s, struct task *t) { ...@@ -584,9 +587,6 @@ void qsched_enqueue(struct qsched *s, struct task *t) {
void qsched_done(struct qsched *s, struct task *t) { void qsched_done(struct qsched *s, struct task *t) {
int k;
struct task *t2;
TIMER_TIC TIMER_TIC
/* Set the task stats. */ /* Set the task stats. */
...@@ -594,17 +594,18 @@ void qsched_done(struct qsched *s, struct task *t) { ...@@ -594,17 +594,18 @@ void qsched_done(struct qsched *s, struct task *t) {
if (!(s->flags & qsched_flag_norecost)) t->cost = t->toc - t->tic; if (!(s->flags & qsched_flag_norecost)) t->cost = t->toc - t->tic;
/* Release this task's locks. */ /* Release this task's locks. */
for (k = 0; k < t->nr_locks; k++) qsched_unlockres(s, t->locks[k]); for (int k = 0; k < t->nr_locks; k++) qsched_unlockres(s, t->locks[k]);
/* Loop over the task's unlocks... */ /* Loop over the task's unlocks... */
for (k = 0; k < t->nr_unlocks; k++) { for (int k = 0; k < t->nr_unlocks; k++) {
/* Get a grip on the unlocked task. */ /* Get a grip on the unlocked task. */
t2 = &s->tasks[t->unlocks[k]]; struct task *t2 = &s->tasks[t->unlocks[k]];
/* Is the unlocked task ready to run? */ /* Is the unlocked task ready to run? */
if (atomic_dec(&t2->wait) == 1 && !(t2->flags & task_flag_skip)) if (atomic_dec(&t2->wait) == 1 && !(t2->flags & task_flag_skip)) {
qsched_enqueue(s, t2); qsched_enqueue(s, t2);
}
} }
/* Decrease the number of tasks in this space. */ /* Decrease the number of tasks in this space. */
...@@ -635,8 +636,6 @@ void qsched_done(struct qsched *s, struct task *t) { ...@@ -635,8 +636,6 @@ void qsched_done(struct qsched *s, struct task *t) {
int qsched_lockres(struct qsched *s, int rid) { int qsched_lockres(struct qsched *s, int rid) {
int finger, finger2;
/* Try to lock the root-level resource. */ /* Try to lock the root-level resource. */
if (s->res[rid].hold || lock_trylock(&s->res[rid].lock)) return 0; if (s->res[rid].hold || lock_trylock(&s->res[rid].lock)) return 0;
...@@ -648,6 +647,7 @@ int qsched_lockres(struct qsched *s, int rid) { ...@@ -648,6 +647,7 @@ int qsched_lockres(struct qsched *s, int rid) {
/* Follow parents and increase their hold counter, but fail /* Follow parents and increase their hold counter, but fail
if any are locked. */ if any are locked. */
int finger;
for (finger = s->res[rid].parent; finger != qsched_res_none; for (finger = s->res[rid].parent; finger != qsched_res_none;
finger = s->res[finger].parent) { finger = s->res[finger].parent) {
if (lock_trylock(&s->res[finger].lock)) break; if (lock_trylock(&s->res[finger].lock)) break;
...@@ -662,9 +662,10 @@ int qsched_lockres(struct qsched *s, int rid) { ...@@ -662,9 +662,10 @@ int qsched_lockres(struct qsched *s, int rid) {
lock_unlock_blind(&s->res[rid].lock); lock_unlock_blind(&s->res[rid].lock);
/* Go back up the tree and undo the holds. */ /* Go back up the tree and undo the holds. */
for (finger2 = s->res[rid].parent; finger2 != finger; for (int finger2 = s->res[rid].parent; finger2 != finger;
finger2 = s->res[finger2].parent) finger2 = s->res[finger2].parent) {
atomic_dec(&s->res[finger2].hold); atomic_dec(&s->res[finger2].hold);
}
/* Fail. */ /* Fail. */
return 0; return 0;
...@@ -672,8 +673,9 @@ int qsched_lockres(struct qsched *s, int rid) { ...@@ -672,8 +673,9 @@ int qsched_lockres(struct qsched *s, int rid) {
} }
/* Otherwise, all went well. */ /* Otherwise, all went well. */
else else {
return 1; return 1;
}
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment