Introduction to Gadgetfs in Linux Systems (cont.) __linux

Source: Internet
Author: User

The previous "Gadgetfs Introduction to Linux System" introduces the basic methods used in Gadgetfs Linux systems, and then describes how to use the two bulk endpoint read and write with single-threaded synchronization Gadgetfs.

Generally speaking, for a read end of Gadgetfs, a write-side can use two threads to separate operations, but in some communication protocols, the upper session requires the receipt of a specified number of packets, the receiver to give confirmation. This confirmation package, in some cases, is the seqno of a package that the receiving party confirms receiving, but at this point the sender may have sent another subsequent packet. Therefore, some packet retransmission may occur, resulting in additional bandwidth consumption, so it is necessary to control the synchronization of the read-write thread. Individuals prefer to use a single thread to simultaneously provide a read-write mechanism, but this requires both the read and write endpoint to support poll operations. The actual survey found that GADGETFS control endpoint support poll operations, but Ep1in&ep1out two endpoint, does not support poll operation, which leads to the above simple ideas can not be achieved. After further investigation, we understand that GADGETFS endpoint file descriptor support Aio,aio can be combined with EVENTFD, so that the poll operation can be implemented, so that in a single thread, read and write two operations synchronized and priority control.

This article mainly describes how to implement the poll operation of the lower read end.

On a: After the completion of the $ep settings, based on the Libaio interface, create an asynchronous read operation of the context:

Io_setup (1, &ioctx);

Create EVENTFD:

EP1EVENTFD = eventfd (0, Efd_nonblock | EFD_CLOEXEC);

Populate the LIBAIO data structure struct IOCB:

Io_prep_pread (IOCB, _ep1out, Driverbuffer, 1024, 0);/* IOCB is a pointer to the struct IOCB, _ep1out is the read-side fd,driverbuffer size 1024*/

Set the EVENTFD for AIO

IO_SET_EVENTFD (IOCB, EP1EVENTFD);

Submit the AIO read operation:

Io_submit (Ioctx, 1, &IOCB);

You can then perform a poll operation on EVENTFD to listen for data arrival.

After the poll returns, the data has been written to the Driverbuffer, followed by the following processing:

struct Io_event _event;

struct Timespec _timeout = {0, 0};

uint64_t _num;

Io_getevents (ioctx, 0, 1, &_event, &_timeout); * Get the basic information of the arrival data, _event.res for the length of the data * *

Read (EP1EVENTFD, &_num, sizeof (uint64_t));/* Clear EVENTFD * *

Io_submit (Ioctx, 1, &IOCB);/* Resubmit, receive next data * *

Write operations can take any other mechanism, as long as the guarantee from the same thread execution, no longer repeat.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.