Esempio n. 1
0
        public unsafe void SubmissionWithInvalidArgumentsDoesNotIncrementDropped()
        {
            var r = new ConcurrentRing(8);

            Assert.True(r.TryAcquireSubmission(out var submission));
            submission.PrepareNop(1u);
            r.Release(submission);

            Assert.True(r.TryAcquireSubmission(out submission));
            // prepare submission with invalid parameters
            submission.PrepareReadWrite(99, -1, (void *)IntPtr.Zero, -12, 0, 0, 2u, SubmissionOption.None);
            r.Release(submission);

            Assert.True(r.TryAcquireSubmission(out submission));
            submission.PrepareNop(3u);
            r.Release(submission);

            Assert.True(r.TryAcquireSubmission(out submission));
            submission.PrepareNop(4u);
            r.Release(submission);

            Assert.Equal(SubmitResult.SubmittedPartially, r.SubmitAndWait(3, out var submitted));
            Assert.Equal(2u, submitted);

            Assert.True(r.TryRead(out var c));
            Assert.Equal(1u, c.UserData);

            Assert.True(r.TryRead(out c));
            Assert.Equal(2u, c.UserData);
            Assert.Equal(EINVAL, -c.Result);

            // Submissions after invalid one are ignored by kernel without dropped being incremented
            Assert.False(r.TryRead(out _));

            // Our ring size is 8 with 2 SQE still unsubmitted... we should only be able to prepare 6 additional SQEs
            for (uint i = 0; i < 6; i++)
            {
                Assert.True(r.TryAcquireSubmission(out submission));
                submission.PrepareNop(5 + i);
                r.Release(submission);
            }
            Assert.False(r.TryAcquireSubmission(out submission)); // This would overwrite the previously unsubmitted SQE

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.Submit(out submitted));
            Assert.Equal(8u, submitted);

            for (uint i = 0; i < 8; i++)
            {
                Assert.True(r.TryRead(out c));
                Assert.Equal(3 + i, c.UserData);
            }
        }
Esempio n. 2
0
 public void PrepSubmitReadConcurrent()
 {
     _concurrentRing.TryAcquireSubmission(out var s);
     s.PrepareNop();
     _concurrentRing.Release(s);
     _concurrentRing.Submit(out _);
     _concurrentRing.TryRead(out _);
 }
Esempio n. 3
0
        public void SmokeTestMultiple(int threadCount, int batchSize, int ringSize)
        {
            var r               = new ConcurrentRing(ringSize);
            var threads         = new Thread[threadCount];
            var actionPerThread = ringSize / threadCount / batchSize;

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    Span <Submission> submissions = stackalloc Submission[batchSize];
                    for (int j = 0; j < actionPerThread; j++)
                    {
                        Assert.True(r.TryAcquireSubmissions(submissions));
                        for (int k = 0; k < batchSize; k++)
                        {
                            submissions[k].PrepareNop();
                            r.Release(submissions[k]);
                        }
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.SubmitAndWait((uint)ringSize, out var operationsSubmitted));
            Assert.Equal((uint)ringSize, operationsSubmitted);

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    for (int j = 0; j < actionPerThread * batchSize; j++)
                    {
                        Assert.True(r.TryRead(out var completion));
                        Assert.Equal(0, completion.Result);
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }
        }
Esempio n. 4
0
        public void SmokeTest(int threadCount, int ringSize)
        {
            var r               = new ConcurrentRing(ringSize);
            var threads         = new Thread[threadCount];
            var actionPerThread = ringSize / threadCount;

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    for (int j = 0; j < actionPerThread; j++)
                    {
                        Assert.True(r.TryAcquireSubmission(out var submission));
                        submission.PrepareNop();
                        r.Release(submission);
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.SubmitAndWait((uint)ringSize, out var operationsSubmitted));
            Assert.Equal((uint)ringSize, operationsSubmitted);

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    for (int j = 0; j < actionPerThread; j++)
                    {
                        Assert.True(r.TryRead(out var completion));
                        Assert.Equal(0, completion.Result);
                    }
                });
            }

            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }
        }
Esempio n. 5
0
        private void ReadEventFd()
        {
            Debug.WriteLine("Adding read on eventfd");

            Span <Submission> submissions = stackalloc Submission[2];

            _ring.AcquireSubmissions(submissions);

            submissions[0].PreparePollAdd(_eventfd, (ushort)POLLIN, options: SubmissionOption.Link);
            _ring.Release(submissions[0]);

            submissions[1].PrepareReadV(_eventfd, _eventfdIoVec, 1, userData: EventFdPollMask);
            _ring.Release(submissions[1]);
        }
Esempio n. 6
0
        public void SubmitIntermittedLinkedSubmissions()
        {
            var r = new ConcurrentRing(8);
            Span <Submission> submissions = stackalloc Submission[2];

            Assert.True(r.TryAcquireSubmissions(submissions));

            submissions[0].PrepareNop(options: SubmissionOption.Link);
            r.Release(submissions[0]);

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.Submit(out var submitted));
            Assert.Equal(1u, submitted);

            Assert.True(r.TryRead(out _));

            submissions[1].PrepareNop(options: SubmissionOption.Link);
            r.Release(submissions[1]);

            Assert.Equal(SubmitResult.SubmittedSuccessfully, r.Submit(out submitted));
            Assert.Equal(1u, submitted);

            Assert.True(r.TryRead(out _));
            Assert.False(r.TryRead(out _));
        }