[RFC PATCH 3/4] Indicate if schedular preemption delay request is granted

Prakash Sangappa posted 4 patches 1 week, 3 days ago
[RFC PATCH 3/4] Indicate if schedular preemption delay request is granted
Posted by Prakash Sangappa 1 week, 3 days ago
Indicate to user space if the preemption delay request was granted
or denied.

Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
---
 include/uapi/linux/task_shared.h | 11 +++++++++++
 mm/task_shared.c                 | 14 +++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/task_shared.h b/include/uapi/linux/task_shared.h
index 6e4c664eea60..a0f7ef0c69d0 100644
--- a/include/uapi/linux/task_shared.h
+++ b/include/uapi/linux/task_shared.h
@@ -15,4 +15,15 @@
 struct task_sharedinfo {
 		volatile unsigned short sched_delay;
 };
+
+/*
+ * 'sched_delay'  values:
+ * TASK_PREEMPT_DELAY_REQ - application sets to request preemption delay.
+ * TASK_PREEMPT_DELAY_GRANTED - set by kernel if granted extended time on cpu.
+ * TASK_PREEMPT_DELAY_DENIED- set by kernel if not granted because the
+ *     application requested preemption delay again within the extended time.
+ */
+#define TASK_PREEMPT_DELAY_REQ		1
+#define TASK_PREEMPT_DELAY_GRANTED	2
+#define TASK_PREEMPT_DELAY_DENIED	3
 #endif
diff --git a/mm/task_shared.c b/mm/task_shared.c
index 575b335d6879..5b8a068a6b44 100644
--- a/mm/task_shared.c
+++ b/mm/task_shared.c
@@ -279,13 +279,21 @@ bool taskshrd_delay_resched(void)
 	if(shrdp == NULL || shrdp->kaddr == NULL)
 		return false;
 
-	if (t->taskshrd_sched_delay)
+	if (t->taskshrd_sched_delay) {
+		if (shrdp->kaddr->ts.sched_delay
+				== TASK_PREEMPT_DELAY_REQ) {
+			/* not granted */
+			shrdp->kaddr->ts.sched_delay
+				= TASK_PREEMPT_DELAY_DENIED;
+		}
 		return false;
+	}
 
-	if (!(shrdp->kaddr->ts.sched_delay))
+	if (shrdp->kaddr->ts.sched_delay != TASK_PREEMPT_DELAY_REQ)
 		return false;
 
-	shrdp->kaddr->ts.sched_delay = 0;
+	/* granted */
+	shrdp->kaddr->ts.sched_delay = TASK_PREEMPT_DELAY_GRANTED;
 	t->taskshrd_sched_delay = 1;
 
 	return true;
-- 
2.43.5