Repository navigation
Expand file tree
/
Copy pathneuron_crwl.h
More file actions
113 lines (96 loc) · 3.35 KB
/
Copy pathneuron_crwl.h
File metadata and controls
113 lines (96 loc) · 3.35 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
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright 2021, Amazon.com, Inc. or its affiliates. All Rights Reserved
*/
#ifndef NEURON_CRWL_H
#define NEURON_CRWL_H
#include <linux/kernel.h>
#include <linux/types.h>
#include "neuron_ioctl.h"
struct neuron_crwl {
struct mutex lock;
struct neuron_uuid uuid; // UUID of currently running model
volatile bool writer_acquired; // true if exclusive access is taken by a process
pid_t writer_pid; // last pid which updated the model
volatile u64 reader_count; // total number of outstanding readers.
};
/**
* ncrwl_nc_range_mark() - Find free NCs of given count, acquire and return as bitmap.
*
* @param nc_count: Number of free NC need to acquire.
* @param start_nc_index: Starting NC index from where search should start.
* @param end_nc_index: Last NC index where search should end.
* @param max_range_available: Maximum number of NC cores available. (valid only on failure)
* @param result: Resulting acquired NC bitmap will be stored here. Caller is expected to zero prior to call
*
* @return 0 on success, negative error code on failure.
*/
int ncrwl_nc_range_mark(u32 nc_count, u32 start_nc_index, u32 end_nc_index,
u32 *max_range_available, volatile long unsigned int *result);
/**
* ncrwl_nc_range_mark() - Release one or more NC acquired.
*
* @param free: Map of NCs to release.
*
*/
void ncrwl_nc_range_unmark(volatile long unsigned int *bitmap);
/**
* ncrwl_nc_range_pid_get( uint32_t nc_index, pid_t *pid)
*
* @param nc_index: core index which we want to return the owner pid
* @param *pid: return pid value. 0 = no owner.
*
*/
int ncrwl_nc_range_pid_get(uint32_t nc_index, pid_t *pid);
/**
* ncrwl_range_mark_cnt_get() - return the count of cores that have been marked
*
*/
int ncrwl_range_mark_cnt_get(void);
/**
* ncrwl_reader_enter() - Takes reader lock of given neuron core.
*
* @nd: Neuron device.
* @nc_index: Neuron Core Index
* @uuid: Unique Identifier used by writer.
*
* @return 0 on success, negative error code on failure to take the lock.
*/
int ncrwl_reader_enter(struct neuron_device *nd, u32 nc_index, struct neuron_uuid uuid);
/**
* ncrwl_reader_exit() - Releases reader lock of given neuron core.
*
* @nd: Neuron device.
* @nc_index: Neuron Core Index
* @uuid: Unique Identifier used by writer.
*
* @return 0 on success, negative error code on failure to release the lock.
*/
int ncrwl_reader_exit(struct neuron_device *nd, u32 nc_index, struct neuron_uuid uuid);
/**
* ncrwl_writer_enter() - Takes writer lock of given neuron core.
*
* @nd: Neuron device.
* @nc_index: Neuron Core Index
* @uuid: Unique Identifier to identify the model.
*
* @return 0 on success, negative error code on failure to take the lock.
*/
int ncrwl_writer_enter(struct neuron_device *nd, u32 nc_index, struct neuron_uuid uuid);
/**
* ncrwl_writer_downgrade() - Downgrades given NC's write lock to read lock.
*
* @nd: Neuron device.
* @nc_index: Neuron Core Index
* @uuid: Unique Identifier used during ncrwl_writer_enter().
*
* @return 0 on success, negative error code on failure to release the lock.
*/
int ncrwl_writer_downgrade(struct neuron_device *nd, u32 nc_index, struct neuron_uuid uuid);
/**
* ncrwl_release_current_process() - Cleanup crwl for all cores owned by the current process.
*
* @nd: Neuron device.
*/
void ncrwl_release_current_process(struct neuron_device *nd);
#endif