test-spinlock-contention.patch
text/x-diff
Filename: test-spinlock-contention.patch
Type: text/x-diff
Part: 0
Patch
Format: unified
| File | + | − |
|---|---|---|
| src/test/modules/test_shm_mq/setup.c | 1 | 0 |
| src/test/modules/test_shm_mq/test_shm_mq.h | 1 | 0 |
| src/test/modules/test_shm_mq/worker.c | 11 | 4 |
diff --git a/src/test/modules/test_shm_mq/setup.c b/src/test/modules/test_shm_mq/setup.c
index e05e97c6de..d535dbe408 100644
--- a/src/test/modules/test_shm_mq/setup.c
+++ b/src/test/modules/test_shm_mq/setup.c
@@ -135,6 +135,7 @@ setup_dynamic_shared_memory(int64 queue_size, int nworkers,
hdr->workers_total = nworkers;
hdr->workers_attached = 0;
hdr->workers_ready = 0;
+ hdr->messages_xfred = 0;
shm_toc_insert(toc, 0, hdr);
/* Set up one message queue per worker, plus one. */
diff --git a/src/test/modules/test_shm_mq/test_shm_mq.h b/src/test/modules/test_shm_mq/test_shm_mq.h
index a666121834..ff35211811 100644
--- a/src/test/modules/test_shm_mq/test_shm_mq.h
+++ b/src/test/modules/test_shm_mq/test_shm_mq.h
@@ -32,6 +32,7 @@ typedef struct
int workers_total;
int workers_attached;
int workers_ready;
+ uint64 messages_xfred;
} test_shm_mq_header;
/* Set up dynamic shared memory and background workers for test run. */
diff --git a/src/test/modules/test_shm_mq/worker.c b/src/test/modules/test_shm_mq/worker.c
index 9b037b98fe..5aceb8ca73 100644
--- a/src/test/modules/test_shm_mq/worker.c
+++ b/src/test/modules/test_shm_mq/worker.c
@@ -31,7 +31,8 @@
static void attach_to_queues(dsm_segment *seg, shm_toc *toc,
int myworkernumber, shm_mq_handle **inqhp,
shm_mq_handle **outqhp);
-static void copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh);
+static void copy_messages(volatile test_shm_mq_header *hdr,
+ shm_mq_handle *inqh, shm_mq_handle *outqh);
/*
* Background worker entrypoint.
@@ -131,7 +132,7 @@ test_shm_mq_main(Datum main_arg)
SetLatch(®istrant->procLatch);
/* Do the work. */
- copy_messages(inqh, outqh);
+ copy_messages(hdr, inqh, outqh);
/*
* We're done. For cleanliness, explicitly detach from the shared memory
@@ -173,7 +174,8 @@ attach_to_queues(dsm_segment *seg, shm_toc *toc, int myworkernumber,
* after this point is cleanup.
*/
static void
-copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh)
+copy_messages(volatile test_shm_mq_header *hdr,
+ shm_mq_handle *inqh, shm_mq_handle *outqh)
{
Size len;
void *data;
@@ -189,7 +191,12 @@ copy_messages(shm_mq_handle *inqh, shm_mq_handle *outqh)
if (res != SHM_MQ_SUCCESS)
break;
- /* Send it back out. */
+ /* Create some contention on the mutex. */
+ SpinLockAcquire(&hdr->mutex);
+ ++hdr->messages_xfred;
+ SpinLockRelease(&hdr->mutex);
+
+ /* Send the message back out. */
res = shm_mq_send(outqh, len, data, false, true);
if (res != SHM_MQ_SUCCESS)
break;