Skip to content

Commit 12cc5f9

Browse files
Umang Jaingregkh
authored andcommitted
staging: vc04_services: Move spinlocks to vchiq_state
The msg_queue_spinlock, quota_spinlock and bulk_waiter_spinlock are allocated globally. Instead move them to struct vchiq_state and initialise them in vchiq_init_state(). Signed-off-by: Umang Jain <[email protected]> Reviewed-by: Stefan Wahren <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6d0ef32 commit 12cc5f9

File tree

5 files changed

+47
-41
lines changed

5 files changed

+47
-41
lines changed

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#define KEEPALIVE_VER 1
6060
#define KEEPALIVE_VER_MIN KEEPALIVE_VER
6161

62-
DEFINE_SPINLOCK(msg_queue_spinlock);
6362
struct vchiq_state g_state;
6463

6564
/*
@@ -985,9 +984,9 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl
985984
* This is not a retry of the previous one.
986985
* Cancel the signal when the transfer completes.
987986
*/
988-
spin_lock(&bulk_waiter_spinlock);
987+
spin_lock(&service->state->bulk_waiter_spinlock);
989988
bulk->userdata = NULL;
990-
spin_unlock(&bulk_waiter_spinlock);
989+
spin_unlock(&service->state->bulk_waiter_spinlock);
991990
}
992991
}
993992
} else {
@@ -1004,9 +1003,9 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handl
10041003

10051004
if (bulk) {
10061005
/* Cancel the signal when the transfer completes. */
1007-
spin_lock(&bulk_waiter_spinlock);
1006+
spin_lock(&service->state->bulk_waiter_spinlock);
10081007
bulk->userdata = NULL;
1009-
spin_unlock(&bulk_waiter_spinlock);
1008+
spin_unlock(&service->state->bulk_waiter_spinlock);
10101009
}
10111010
kfree(waiter);
10121011
} else {
@@ -1127,10 +1126,10 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
11271126
reason, header, instance, bulk_userdata);
11281127

11291128
if (header && user_service->is_vchi) {
1130-
spin_lock(&msg_queue_spinlock);
1129+
spin_lock(&service->state->msg_queue_spinlock);
11311130
while (user_service->msg_insert ==
11321131
(user_service->msg_remove + MSG_QUEUE_SIZE)) {
1133-
spin_unlock(&msg_queue_spinlock);
1132+
spin_unlock(&service->state->msg_queue_spinlock);
11341133
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
11351134
DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
11361135
dev_dbg(service->state->dev, "arm: msg queue full\n");
@@ -1167,7 +1166,7 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
11671166
return -EINVAL;
11681167
}
11691168
DEBUG_TRACE(SERVICE_CALLBACK_LINE);
1170-
spin_lock(&msg_queue_spinlock);
1169+
spin_lock(&service->state->msg_queue_spinlock);
11711170
}
11721171

11731172
user_service->msg_queue[user_service->msg_insert &
@@ -1186,7 +1185,7 @@ service_callback(struct vchiq_instance *instance, enum vchiq_reason reason,
11861185
skip_completion = true;
11871186
}
11881187

1189-
spin_unlock(&msg_queue_spinlock);
1188+
spin_unlock(&service->state->msg_queue_spinlock);
11901189
complete(&user_service->insert_event);
11911190

11921191
header = NULL;

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ struct vchiq_instance {
9898
struct vchiq_debugfs_node debugfs_node;
9999
};
100100

101-
extern spinlock_t msg_queue_spinlock;
102101
extern struct vchiq_state g_state;
103102

104103
extern struct vchiq_state *

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,6 @@ static inline void check_sizes(void)
149149
BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_MAX_SERVICES);
150150
}
151151

152-
DEFINE_SPINLOCK(bulk_waiter_spinlock);
153-
static DEFINE_SPINLOCK(quota_spinlock);
154-
155152
static unsigned int handle_seq;
156153

157154
static const char *const srvstate_names[] = {
@@ -724,11 +721,11 @@ process_free_data_message(struct vchiq_state *state, u32 *service_found,
724721
struct vchiq_service_quota *quota = &state->service_quotas[port];
725722
int count;
726723

727-
spin_lock(&quota_spinlock);
724+
spin_lock(&state->quota_spinlock);
728725
count = quota->message_use_count;
729726
if (count > 0)
730727
quota->message_use_count = count - 1;
731-
spin_unlock(&quota_spinlock);
728+
spin_unlock(&state->quota_spinlock);
732729

733730
if (count == quota->message_quota) {
734731
/*
@@ -747,11 +744,11 @@ process_free_data_message(struct vchiq_state *state, u32 *service_found,
747744
/* Set the found bit for this service */
748745
BITSET_SET(service_found, port);
749746

750-
spin_lock(&quota_spinlock);
747+
spin_lock(&state->quota_spinlock);
751748
count = quota->slot_use_count;
752749
if (count > 0)
753750
quota->slot_use_count = count - 1;
754-
spin_unlock(&quota_spinlock);
751+
spin_unlock(&state->quota_spinlock);
755752

756753
if (count > 0) {
757754
/*
@@ -837,11 +834,11 @@ process_free_queue(struct vchiq_state *state, u32 *service_found,
837834
if (data_found) {
838835
int count;
839836

840-
spin_lock(&quota_spinlock);
837+
spin_lock(&state->quota_spinlock);
841838
count = state->data_use_count;
842839
if (count > 0)
843840
state->data_use_count = count - 1;
844-
spin_unlock(&quota_spinlock);
841+
spin_unlock(&state->quota_spinlock);
845842
if (count == state->data_quota)
846843
complete(&state->data_quota_event);
847844
}
@@ -940,7 +937,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
940937

941938
quota = &state->service_quotas[service->localport];
942939

943-
spin_lock(&quota_spinlock);
940+
spin_lock(&state->quota_spinlock);
944941

945942
/*
946943
* Ensure this service doesn't use more than its quota of
@@ -955,14 +952,14 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
955952
while ((tx_end_index != state->previous_data_index) &&
956953
(state->data_use_count == state->data_quota)) {
957954
VCHIQ_STATS_INC(state, data_stalls);
958-
spin_unlock(&quota_spinlock);
955+
spin_unlock(&state->quota_spinlock);
959956
mutex_unlock(&state->slot_mutex);
960957

961958
if (wait_for_completion_interruptible(&state->data_quota_event))
962959
return -EAGAIN;
963960

964961
mutex_lock(&state->slot_mutex);
965-
spin_lock(&quota_spinlock);
962+
spin_lock(&state->quota_spinlock);
966963
tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos + stride - 1);
967964
if ((tx_end_index == state->previous_data_index) ||
968965
(state->data_use_count < state->data_quota)) {
@@ -975,7 +972,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
975972
while ((quota->message_use_count == quota->message_quota) ||
976973
((tx_end_index != quota->previous_tx_index) &&
977974
(quota->slot_use_count == quota->slot_quota))) {
978-
spin_unlock(&quota_spinlock);
975+
spin_unlock(&state->quota_spinlock);
979976
dev_dbg(state->dev,
980977
"core: %d: qm:%d %s,%zx - quota stall (msg %d, slot %d)\n",
981978
state->id, service->localport, msg_type_str(type), size,
@@ -993,11 +990,11 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
993990
mutex_unlock(&state->slot_mutex);
994991
return -EHOSTDOWN;
995992
}
996-
spin_lock(&quota_spinlock);
993+
spin_lock(&state->quota_spinlock);
997994
tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos + stride - 1);
998995
}
999996

1000-
spin_unlock(&quota_spinlock);
997+
spin_unlock(&state->quota_spinlock);
1001998
}
1002999

10031000
header = reserve_space(state, stride, flags & QMFLAGS_IS_BLOCKING);
@@ -1040,7 +1037,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
10401037
header->data,
10411038
min_t(size_t, 16, callback_result));
10421039

1043-
spin_lock(&quota_spinlock);
1040+
spin_lock(&state->quota_spinlock);
10441041
quota->message_use_count++;
10451042

10461043
tx_end_index =
@@ -1066,7 +1063,7 @@ queue_message(struct vchiq_state *state, struct vchiq_service *service,
10661063
slot_use_count = 0;
10671064
}
10681065

1069-
spin_unlock(&quota_spinlock);
1066+
spin_unlock(&state->quota_spinlock);
10701067

10711068
if (slot_use_count)
10721069
dev_dbg(state->dev, "core: %d: qm:%d %s,%zx - slot_use->%d (hdr %p)\n",
@@ -1322,13 +1319,13 @@ notify_bulks(struct vchiq_service *service, struct vchiq_bulk_queue *queue,
13221319
if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
13231320
struct bulk_waiter *waiter;
13241321

1325-
spin_lock(&bulk_waiter_spinlock);
1322+
spin_lock(&service->state->bulk_waiter_spinlock);
13261323
waiter = bulk->userdata;
13271324
if (waiter) {
13281325
waiter->actual = bulk->actual;
13291326
complete(&waiter->event);
13301327
}
1331-
spin_unlock(&bulk_waiter_spinlock);
1328+
spin_unlock(&service->state->bulk_waiter_spinlock);
13321329
} else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) {
13331330
enum vchiq_reason reason =
13341331
get_bulk_reason(bulk);
@@ -2169,6 +2166,10 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero, s
21692166
mutex_init(&state->sync_mutex);
21702167
mutex_init(&state->bulk_transfer_mutex);
21712168

2169+
spin_lock_init(&state->msg_queue_spinlock);
2170+
spin_lock_init(&state->bulk_waiter_spinlock);
2171+
spin_lock_init(&state->quota_spinlock);
2172+
21722173
init_completion(&state->slot_available_event);
21732174
init_completion(&state->slot_remove_event);
21742175
init_completion(&state->data_quota_event);

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/kthread.h>
1212
#include <linux/kref.h>
1313
#include <linux/rcupdate.h>
14+
#include <linux/spinlock_types.h>
1415
#include <linux/wait.h>
1516

1617
#include "../../include/linux/raspberrypi/vchiq.h"
@@ -348,6 +349,12 @@ struct vchiq_state {
348349

349350
struct mutex bulk_transfer_mutex;
350351

352+
spinlock_t msg_queue_spinlock;
353+
354+
spinlock_t bulk_waiter_spinlock;
355+
356+
spinlock_t quota_spinlock;
357+
351358
/*
352359
* Indicates the byte position within the stream from where the next
353360
* message will be read. The least significant bits are an index into

drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,25 @@ static int vchiq_ioc_dequeue_message(struct vchiq_instance *instance,
220220
goto out;
221221
}
222222

223-
spin_lock(&msg_queue_spinlock);
223+
spin_lock(&service->state->msg_queue_spinlock);
224224
if (user_service->msg_remove == user_service->msg_insert) {
225225
if (!args->blocking) {
226-
spin_unlock(&msg_queue_spinlock);
226+
spin_unlock(&service->state->msg_queue_spinlock);
227227
DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
228228
ret = -EWOULDBLOCK;
229229
goto out;
230230
}
231231
user_service->dequeue_pending = 1;
232232
ret = 0;
233233
do {
234-
spin_unlock(&msg_queue_spinlock);
234+
spin_unlock(&service->state->msg_queue_spinlock);
235235
DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
236236
if (wait_for_completion_interruptible(&user_service->insert_event)) {
237237
dev_dbg(service->state->dev, "arm: DEQUEUE_MESSAGE interrupted\n");
238238
ret = -EINTR;
239239
break;
240240
}
241-
spin_lock(&msg_queue_spinlock);
241+
spin_lock(&service->state->msg_queue_spinlock);
242242
} while (user_service->msg_remove == user_service->msg_insert);
243243

244244
if (ret)
@@ -247,15 +247,15 @@ static int vchiq_ioc_dequeue_message(struct vchiq_instance *instance,
247247

248248
if (WARN_ON_ONCE((int)(user_service->msg_insert -
249249
user_service->msg_remove) < 0)) {
250-
spin_unlock(&msg_queue_spinlock);
250+
spin_unlock(&service->state->msg_queue_spinlock);
251251
ret = -EINVAL;
252252
goto out;
253253
}
254254

255255
header = user_service->msg_queue[user_service->msg_remove &
256256
(MSG_QUEUE_SIZE - 1)];
257257
user_service->msg_remove++;
258-
spin_unlock(&msg_queue_spinlock);
258+
spin_unlock(&service->state->msg_queue_spinlock);
259259

260260
complete(&user_service->remove_event);
261261
if (!header) {
@@ -340,9 +340,9 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_instance *instance,
340340
!waiter->bulk_waiter.bulk) {
341341
if (waiter->bulk_waiter.bulk) {
342342
/* Cancel the signal when the transfer completes. */
343-
spin_lock(&bulk_waiter_spinlock);
343+
spin_lock(&service->state->bulk_waiter_spinlock);
344344
waiter->bulk_waiter.bulk->userdata = NULL;
345-
spin_unlock(&bulk_waiter_spinlock);
345+
spin_unlock(&service->state->bulk_waiter_spinlock);
346346
}
347347
kfree(waiter);
348348
ret = 0;
@@ -1246,22 +1246,22 @@ static int vchiq_release(struct inode *inode, struct file *file)
12461246
break;
12471247
}
12481248

1249-
spin_lock(&msg_queue_spinlock);
1249+
spin_lock(&service->state->msg_queue_spinlock);
12501250

12511251
while (user_service->msg_remove != user_service->msg_insert) {
12521252
struct vchiq_header *header;
12531253
int m = user_service->msg_remove & (MSG_QUEUE_SIZE - 1);
12541254

12551255
header = user_service->msg_queue[m];
12561256
user_service->msg_remove++;
1257-
spin_unlock(&msg_queue_spinlock);
1257+
spin_unlock(&service->state->msg_queue_spinlock);
12581258

12591259
if (header)
12601260
vchiq_release_message(instance, service->handle, header);
1261-
spin_lock(&msg_queue_spinlock);
1261+
spin_lock(&service->state->msg_queue_spinlock);
12621262
}
12631263

1264-
spin_unlock(&msg_queue_spinlock);
1264+
spin_unlock(&service->state->msg_queue_spinlock);
12651265

12661266
vchiq_service_put(service);
12671267
}

0 commit comments

Comments
 (0)