[Nexus 6P Original Android Development] szale9001:
So, to [MENTION=3292224]franciscofranco[/MENTION] or anyone else out there who's a programming guru, I took a stab at porting this patch from marlin to angler (disclaimer: not a programmer lol)

https://github.com/franciscofranco/marlin/commit/ed11186da9074b635a8ff63575dc8f92129d9ec6

It does compile and seems to be working on my device, but if I've learned anything tinkering with code, it's that a successful compilation and boot doesn't mean its done properly ;) .

Would anyone mind taking a look at this diff and letting me know if there is anything that should be changed? If it's any good/not totally wrong, maybe franco can merge it into his git.

Subject: [PATCH] mdss: rotator: Use FIFO kthread for rotator work

Bug: 30891496
Change-Id: I65725fd7f8bd2b10543bf3fc3307308d9d11a9c0
Signed-off-by: Naseer Ahmed <naseer@codeaurora.org>
---
drivers/video/msm/mdss/mdss_mdp_rotator.c | 35 ++++++++++++++++++-------------
drivers/video/msm/mdss/mdss_mdp_rotator.h | 3 ++-
2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/video/msm/mdss/mdss_mdp_rotator.c b/drivers/video/msm/mdss/mdss_mdp_rotator.c
index d394dcf0a3be..1b6bca3ad0d0 100644
--- a/drivers/video/msm/mdss/mdss_mdp_rotator.c
+++ b/drivers/video/msm/mdss/mdss_mdp_rotator.c
@@ -30,6 +30,9 @@

#define MAX_ROTATOR_SESSION_ID 0xfffffff

+struct kthread_worker worker;
+struct task_struct *thread;
+
struct mdss_mdp_rot_pipe {
struct mdss_mdp_pipe *pipe;
struct mdss_mdp_rotator_session *active_session;
@@ -49,13 +52,11 @@ struct mdss_mdp_rot_session_mgr {
int pipe_count;
struct mutex pipe_lock;
struct mdss_mdp_rot_pipe rot_pipes[MAX_ROTATOR_PIPE_COUNT];
-
-	struct workqueue_struct *rot_work_queue;
};

static struct mdss_mdp_rot_session_mgr *rot_mgr;
static int mdss_mdp_rotator_finish(struct mdss_mdp_rotator_session *rot);
-static void mdss_mdp_rotator_commit_wq_handler(struct work_struct *work);
+static void mdss_mdp_rotator_commit_work_handler(struct kthread_work *work);
static int mdss_mdp_rotator_busy_wait(struct mdss_mdp_rotator_session *rot,
struct mdss_mdp_pipe *pipe);
static int mdss_mdp_rotator_queue_helper(struct mdss_mdp_rotator_session *rot);
@@ -64,6 +65,8 @@ static struct msm_sync_pt_data *mdss_mdp_rotator_sync_pt_create(

int mdss_mdp_rot_mgr_init(void)
{
+	struct sched_param param = { .sched_priority = 5 };
+
if (rot_mgr) {
pr_debug("rot manager initialized already\n");
return 0;
@@ -78,16 +81,18 @@ int mdss_mdp_rot_mgr_init(void)
mutex_init(&rot_mgr->session_lock);
mutex_init(&rot_mgr->pipe_lock);
INIT_LIST_HEAD(&rot_mgr->queue);
-	rot_mgr->rot_work_queue = alloc_workqueue("rot_commit_workq",
-	WQ_UNBOUND | WQ_HIGHPRI | WQ_MEM_RECLAIM,
-	MAX_ROTATOR_PIPE_COUNT);
-	if (!rot_mgr->rot_work_queue) {
-	pr_err("fail to create rot commit work queue\n");
+	init_kthread_worker(&worker);
+	thread = kthread_run(kthread_worker_fn, &worker, "thread");
+
+	if (IS_ERR(thread)) {
+	pr_err("fail to create rot commit kthread\n");
kfree(rot_mgr);
rot_mgr = NULL;
return -ENOMEM;
}

+	sched_setscheduler(thread, SCHED_FIFO, &param);
+
return 0;
}

@@ -619,7 +624,7 @@ error:
return ret;
}

-static void mdss_mdp_rotator_commit_wq_handler(struct work_struct *work)
+static void mdss_mdp_rotator_commit_work_handler(struct kthread_work *work)
{
struct mdss_mdp_rotator_session *rot;
int ret;
@@ -665,8 +670,8 @@ static struct msm_sync_pt_data *mdss_mdp_rotator_sync_pt_create(
} else {
sync_pt_data->timeline_value = 0;
}
-	INIT_WORK(&rot->commit_work,
-	mdss_mdp_rotator_commit_wq_handler);
+	init_kthread_work(&rot->commit_work,
+	mdss_mdp_rotator_commit_work_handler);
mutex_init(&sync_pt_data->sync_mutex);
return sync_pt_data;
}
@@ -714,7 +719,7 @@ static int mdss_mdp_rotator_queue(struct mdss_mdp_rotator_session *rot)
rot->rot_sync_pt_data->temp_fen,
&rot->rot_sync_pt_data->temp_fen_cnt);
atomic_inc(&rot->rot_sync_pt_data->commit_cnt);
-	queue_work(rot_mgr->rot_work_queue, &rot->commit_work);
+	queue_kthread_work(&worker, &rot->commit_work);
} else {
ret = mdss_mdp_rotator_queue_helper(rot);
}
@@ -935,7 +940,7 @@ static int mdss_mdp_rotator_config_ex(struct msm_fb_data_type *mfd,
return 0;
}

-	flush_work(&rot->commit_work);
+	flush_kthread_work(&rot->commit_work);

mutex_lock(&rot->lock);
ret = mdss_mdp_rotator_config(mfd, rot, req, fmt);
@@ -977,7 +982,7 @@ static int mdss_mdp_rotator_finish(struct mdss_mdp_rotator_session *rot)
{
pr_debug("finish rot id=%x\n", rot->session_id);

-	flush_work(&rot->commit_work);
+	flush_kthread_work(&rot->commit_work);
mdss_mdp_rot_mgr_del_session(rot);

return 0;
@@ -1033,7 +1038,7 @@ int mdss_mdp_rotator_play(struct msm_fb_data_type *mfd,

flgs = rot->flags & MDP_SECURE_OVERLAY_SESSION;

-	flush_work(&rot->commit_work);
+	flush_kthread_work(&rot->commit_work);

mdss_iommu_ctrl(1);
mutex_lock(&rot->lock);
diff --git a/drivers/video/msm/mdss/mdss_mdp_rotator.h b/drivers/video/msm/mdss/mdss_mdp_rotator.h
index ca67ff78f867..c34a55b52470 100644
--- a/drivers/video/msm/mdss/mdss_mdp_rotator.h
+++ b/drivers/video/msm/mdss/mdss_mdp_rotator.h
@@ -13,6 +13,7 @@
#ifndef MDSS_MDP_ROTATOR_H
#define MDSS_MDP_ROTATOR_H

+#include <linux/kthread.h>
#include <linux/types.h>

#include "mdss_mdp.h"
@@ -47,7 +48,7 @@ struct mdss_mdp_rotator_session {
struct list_head head;
struct list_head list;
struct msm_sync_pt_data *rot_sync_pt_data;
-	struct work_struct commit_work;
+	struct kthread_work commit_work;

struct mdp_overlay req_data;
};
--
2.13.0