提交 d5aa2997 编写于 作者: C Chen Hui 提交者: Zheng Zengkai

sched: programmable: Add user interface of task tag

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5KUFB
CVE: NA

--------------------------------

Add user interface of task tag, bridges the information
gap between user-mode and kernel mode.

To do:
  /proc/${pid}/task/${pid}/tag
Signed-off-by: NChen Hui <judy.chenhui@huawei.com>
Signed-off-by: NRen Zhijie <renzhijie2@huawei.com>
上级 b07932e2
...@@ -3644,6 +3644,68 @@ static const struct inode_operations proc_tid_comm_inode_operations = { ...@@ -3644,6 +3644,68 @@ static const struct inode_operations proc_tid_comm_inode_operations = {
.permission = proc_tid_comm_permission, .permission = proc_tid_comm_permission,
}; };
#ifdef CONFIG_BPF_SCHED
static ssize_t pid_tag_write(struct file *file, const char __user *buf,
size_t count, loff_t *offset)
{
struct inode *inode = file_inode(file);
struct task_struct *tsk;
char buffer[PROC_NUMBUF];
int err = 0, tag = 0;
tsk = get_proc_task(inode);
if (!tsk)
return -ESRCH;
memset(buffer, 0, sizeof(buffer));
if (count > sizeof(buffer) - 1)
count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count)) {
err = -EFAULT;
goto out;
}
err = kstrtoint(strstrip(buffer), 0, &tag);
if (err)
goto out;
sched_settag(tsk, tag);
out:
put_task_struct(tsk);
return err < 0 ? err : count;
}
static int pid_tag_show(struct seq_file *m, void *v)
{
struct inode *inode = m->private;
struct task_struct *tsk;
tsk = get_proc_task(inode);
if (!tsk)
return -ESRCH;
seq_printf(m, "%ld\n", tsk->tag);
put_task_struct(tsk);
return 0;
}
static int pid_tag_open(struct inode *inode, struct file *flip)
{
return single_open(flip, pid_tag_show, inode);
}
static const struct file_operations proc_pid_tag_operations = {
.open = pid_tag_open,
.read = seq_read,
.write = pid_tag_write,
.llseek = seq_lseek,
.release = single_release,
};
#endif
/* /*
* Tasks * Tasks
*/ */
...@@ -3751,6 +3813,9 @@ static const struct pid_entry tid_base_stuff[] = { ...@@ -3751,6 +3813,9 @@ static const struct pid_entry tid_base_stuff[] = {
#ifdef CONFIG_ASCEND_SHARE_POOL #ifdef CONFIG_ASCEND_SHARE_POOL
ONE("sp_group", 0444, proc_sp_group_state), ONE("sp_group", 0444, proc_sp_group_state),
#endif #endif
#ifdef CONFIG_BPF_SCHED
REG("tag", 0644, proc_pid_tag_operations),
#endif
}; };
static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx) static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册