From 3a956a573d2ecb9a7520680ec6bcd6f626054488 Mon Sep 17 00:00:00 2001 From: Terje Bergstrom Date: Mon, 11 Dec 2017 11:33:48 -0800 Subject: gpu: nvgpu: Implement abstraction for finding TGID Implement abstraction for finding the process ID of thread currently being run. This is tracked for context switch tracing. In Linux kernel this is implemented by returning TGID. Change-Id: Ia6bcbd92c8cc25467694a35476e5d5f717194105 Signed-off-by: Terje Bergstrom Reviewed-on: https://git-master.nvidia.com/r/1615985 Reviewed-by: svc-mobile-coverity GVS: Gerrit_Virtual_Submit Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/Makefile | 1 + drivers/gpu/nvgpu/common/linux/os_sched.c | 21 ++++++++++++++++++ drivers/gpu/nvgpu/gk20a/tsg_gk20a.c | 3 ++- drivers/gpu/nvgpu/include/nvgpu/os_sched.h | 34 ++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/nvgpu/common/linux/os_sched.c create mode 100644 drivers/gpu/nvgpu/include/nvgpu/os_sched.h diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile index 8a95065f..47c7e7d7 100644 --- a/drivers/gpu/nvgpu/Makefile +++ b/drivers/gpu/nvgpu/Makefile @@ -49,6 +49,7 @@ nvgpu-y := \ common/linux/channel.o \ common/linux/ce2.o \ common/linux/sim.o \ + common/linux/os_sched.o \ common/mm/nvgpu_allocator.o \ common/mm/bitmap_allocator.o \ common/mm/buddy_allocator.o \ diff --git a/drivers/gpu/nvgpu/common/linux/os_sched.c b/drivers/gpu/nvgpu/common/linux/os_sched.c new file mode 100644 index 00000000..ddaaad0f --- /dev/null +++ b/drivers/gpu/nvgpu/common/linux/os_sched.c @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include + +#include + +int nvgpu_current_pid(struct gk20a *g) +{ + return current->tgid; +} diff --git a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c index 4efcfda8..64d521a0 100644 --- a/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/tsg_gk20a.c @@ -22,6 +22,7 @@ #include #include +#include #include "gk20a.h" #include "tsg_gk20a.h" @@ -286,7 +287,7 @@ struct tsg_gk20a *gk20a_tsg_open(struct gk20a *g) tsg->timeslice_timeout = 0; tsg->timeslice_scale = 0; tsg->runlist_id = ~0; - tsg->tgid = current->tgid; + tsg->tgid = nvgpu_current_pid(g); if (g->ops.fifo.init_eng_method_buffers) g->ops.fifo.init_eng_method_buffers(g, tsg); diff --git a/drivers/gpu/nvgpu/include/nvgpu/os_sched.h b/drivers/gpu/nvgpu/include/nvgpu/os_sched.h new file mode 100644 index 00000000..61cee4ad --- /dev/null +++ b/drivers/gpu/nvgpu/include/nvgpu/os_sched.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef __NVGPU_OS_SCHED_H__ +#define __NVGPU_OS_SCHED_H__ + +struct gk20a; + +/** + * nvgpu_current_pid - Query the id of current process + * + */ +int nvgpu_current_pid(struct gk20a *g); + +#endif /* __NVGPU_OS_SCHED_H__ */ -- cgit v1.2.2