-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathneuron_pid.h
More file actions
118 lines (102 loc) · 3.13 KB
/
neuron_pid.h
File metadata and controls
118 lines (102 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2021, Amazon.com, Inc. or its affiliates. All Rights Reserved
*/
#ifndef NEURON_PID_H
#define NEURON_PID_H
#include <linux/sched.h>
#include "neuron_arch.h"
#include "neuron_mempool.h"
#include "neuron_ring.h"
#include "neuron_core.h"
#include "neuron_ioctl.h"
struct neuron_attached_process {
pid_t pid; // pid which attached to this process
int open_count; // how many time this process opened this device.
size_t memory_used[MEM_LOC_COUNT]; // currently allocated memory size
void * task; // pointer to task
};
/**
* npid_print_usage() - print all attached process info.
*
* @nd: Neuron device
*/
void npid_print_usage(struct neuron_device *nd);
/**
* npid_is_attached_task() - checks whether current task is opened to the given device.
*
* @nd: Neuron device
*
* @return 0 if process is not attached, open_count by the processs otherwise.
*/
int npid_is_attached_task(struct neuron_device *nd);
/**
* npid_is_attached() - checks whether current pid is opened to the given device.
*
* @nd: Neuron device
*
* @return 0 if process is not attached, open_count by the processs otherwise.
*/
int npid_is_attached(struct neuron_device *nd);
/** npid_attached_process_count() - Returns number of processes attached to the given device.
*
* @nd: Neuron device
*
* @return Number of processes attached to the device.
*/
int npid_attached_process_count(struct neuron_device *nd);
/**
* npid_attach() - Attach current process to neuron device.
*
* @nd: Neuron device
*
* @return true if the current process attached successfully, false otherwise.
*/
bool npid_attach(struct neuron_device *nd);
/**
* npid_detach() - Detach current process from neuron device.
*
* @nd: Neuron device
*
* @return number of open reference count for the current process on the device.
*/
int npid_detach(struct neuron_device *nd);
/**
* npid_find_process_slot() - Find current process's slot index in the attached process array.
*
* @param nd - Neuron device
*
* @return -1 on failure, slot index on success
*/
int npid_find_process_slot(struct neuron_device *nd);
/**
* npid_add_allocated_memory() - Adds allocated memory for the current pid
*
* @nd: Neuron device
* @location: Memory location
* @amount: Amount to increase with
*
* @return 0 if successful, -1 if current PID not found
*/
int npid_add_allocated_memory(struct neuron_device *nd, enum mem_location location, size_t amount);
/**
* npid_dec_allocated_memory() - Decreases allocated memory for the current pid
*
* @nd: Neuron device
* @location: Memory location
* @amount: Amount to decrease with
*
* @return 0 if successful, -1 if current PID not found
*/
int npid_dec_allocated_memory(struct neuron_device *nd, enum mem_location location, size_t amount);
/**
* npid_get_allocated_memory() - Gets allocated memory for the given pid
*
* @nd: Neuron device
* @pid: PID for which to retrieve memory usage
* @host_memory[out]: Amount of host memory in use
* @device_memory[out]: Amount of device memory in use
*
*/
int npid_get_allocated_memory(struct neuron_device *nd, pid_t pid, size_t *host_memory, size_t *device_memory);
#endif