From 8bd73246f393441a84fc5b9d3efbf97583492cb5 Mon Sep 17 00:00:00 2001 From: Sagar Kadamati Date: Thu, 28 Mar 2019 16:13:32 +0530 Subject: [PATCH] nvgpu: unify sched unit with qnx move sched funcs from nvgpu.c to os_sched.c, so qnx can use it JIRA NVGPU-2134 Change-Id: I1a1a0773d3ff9a3e9a76ae7b730ec8d1b700ea14 Signed-off-by: Sagar Kadamati Reviewed-on: https://git-master.nvidia.com/r/2083808 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/Makefile.sources | 3 +- drivers/gpu/nvgpu/os/posix/nvgpu.c | 33 +-------------- drivers/gpu/nvgpu/os/posix/os_sched.c | 58 +++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 33 deletions(-) create mode 100644 drivers/gpu/nvgpu/os/posix/os_sched.c diff --git a/drivers/gpu/nvgpu/Makefile.sources b/drivers/gpu/nvgpu/Makefile.sources index c3579ba3d..7687a932e 100644 --- a/drivers/gpu/nvgpu/Makefile.sources +++ b/drivers/gpu/nvgpu/Makefile.sources @@ -56,7 +56,8 @@ srcs += os/posix/bug.c \ os/posix/cond.c \ os/posix/lock.c \ os/posix/thread.c \ - os/posix/bsearch.c + os/posix/bsearch.c \ + os/posix/os_sched.c srcs += common/sim.c \ common/sim_pci.c \ diff --git a/drivers/gpu/nvgpu/os/posix/nvgpu.c b/drivers/gpu/nvgpu/os/posix/nvgpu.c index de1becf31..f9cd2aacd 100644 --- a/drivers/gpu/nvgpu/os/posix/nvgpu.c +++ b/drivers/gpu/nvgpu/os/posix/nvgpu.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2018-2019, 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"), @@ -36,37 +36,6 @@ #include "os_posix.h" -int nvgpu_current_pid(struct gk20a *g) -{ - /* - * In the kernel this gets us the PID of the calling process for IOCTLs. - * But since we are in userspace this doesn't quite mean the same thing. - * This simply returns the PID of the currently running process. - */ - return (int)getpid(); -} - -int nvgpu_current_tid(struct gk20a *g) -{ - /* - * In POSIX thread ID is not the same as a process ID. In Linux threads - * and processes are represented by the same thing, but userspace can't - * really rely on that. - * - * We can, however, get a pthread_t for a given thread. But this - * pthread_t need not have any relation to the underlying system's - * representation of "threads". - */ - return (int)pthread_self(); -} - -void __nvgpu_print_current(struct gk20a *g, const char *func_name, int line, - void *ctx, enum nvgpu_log_type type) -{ - __nvgpu_log_msg(g, func_name, line, type, - "Current process: (nvgpu userspace)"); -} - /* * Somewhat meaningless in userspace... */ diff --git a/drivers/gpu/nvgpu/os/posix/os_sched.c b/drivers/gpu/nvgpu/os/posix/os_sched.c new file mode 100644 index 000000000..a1e62f9a1 --- /dev/null +++ b/drivers/gpu/nvgpu/os/posix/os_sched.c @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved. + * + * NVIDIA Corporation and its licensors retain all intellectual property and + * proprietary rights in and to this software and related documentation. Any + * use, reproduction, disclosure or distribution of this software and related + * documentation without an express license agreement from NVIDIA Corporation + * is strictly prohibited. + */ + +#include + +#if defined(__NVGPU_POSIX__) +#define __USE_GNU +#else +#define __EXT_QNX +#endif + +#include +#include + +#define CURRENT_NAME_LEN 30 + +int nvgpu_current_pid(struct gk20a *g) +{ + /* + * In the kernel this gets us the PID of the calling process for IOCTLs. + * But since we are in userspace this doesn't quite mean the same thing. + * This simply returns the PID of the currently running process. + */ + return (int)getpid(); +} + +int nvgpu_current_tid(struct gk20a *g) +{ + /* + * In POSIX thread ID is not the same as a process ID. In Linux threads + * and processes are represented by the same thing, but userspace can't + * really rely on that. + * + * We can, however, get a pthread_t for a given thread. But this + * pthread_t need not have any relation to the underlying system's + * representation of "threads". + */ + return (int)pthread_self(); +} + +void __nvgpu_print_current(struct gk20a *g, const char *func_name, int line, + void *ctx, enum nvgpu_log_type type) +{ + char current_tname[CURRENT_NAME_LEN]; + + /* pthread_getname_np() will return null terminated string on success */ + if (pthread_getname_np(0, current_tname, CURRENT_NAME_LEN) == 0) + __nvgpu_log_msg(g, func_name, line, type, current_tname); + else + __nvgpu_log_msg(g, func_name, line, type, "(unknown process)"); +}