Michael, Would you please give an example or two how these two flags DESC_DRIVER and DESC_WRAP are used together? Like others, I am confused by the description and still don?t quite grok it. Steven On 9/25/17, 3:24 PM, "virtio-dev at lists.oasis-open.org on behalf of Michael S. Tsirkin" <virtio-dev at lists.oasis-open.org on behalf of mst at redhat.com> wrote: On Wed, Sep 20, 2017 at 09:11:57AM +0000, Liang, Cunming wrote: > Hi Michael, > > > -----Original Message----- > > From: virtio-dev at lists.oasis-open.org [mailto:virtio-dev at lists.oasis-open.org] > > On Behalf Of Michael S. Tsirkin > > Sent: Sunday, September 10, 2017 1:06 PM > > To: virtio-dev at lists.oasis-open.org > > Cc: virtualization at lists.linux-foundation.org > > Subject: [virtio-dev] packed ring layout proposal v3 > > > [...] > > * Descriptor ring: > > > > Driver writes descriptors with unique index values and DESC_DRIVER set in > > flags. > > Descriptors are written in a ring order: from start to end of ring, wrapping > > around to the beginning. > > Device writes used descriptors with correct len, index, and DESC_HW clear. > > Again descriptors are written in ring order. This might not be the same order > > of driver descriptors, and not all descriptors have to be written out. > > > > Driver and device are expected to maintain (internally) a wrap-around bit, > > starting at 0 and changing value each time they start writing out descriptors > > at the beginning of the ring. This bit is passed as DESC_WRAP bit in the flags > > field. > > One simple question there, trying to understand the usage of DESC_WRAP flag. > > DESC_WRAP bit is a new flag since v2. It's used to address 'non power-of-2 ring sizes' mentioned in v2? > > Being confused by the statement of wrap-around bit here, it's an internal wrap-around counter represented by single bit (0/1)? > DESC_WRAP can appear on any descriptor entry in the ring, why it highlights changing value at the beginning of the ring? No, this is necessary if not all descriptors are overwritten by device after they are used. Each time driver overwrites a descriptor, the value in DESC_WRAP changes which makes it possible for device to detect that there's a new descriptor. > > > > Flags are always set/cleared last. > > > > Note that driver can write descriptors out in any order, but device will not > > execute descriptor X+1 until descriptor X has been read as valid. > > > > Driver operation: > > > [...] > > > > DESC_WRAP - device uses this field to detect descriptor change by driver. > > Device uses this field to detect change of wrap-around boundary by driver? > > [...] > > > > Device operation (using descriptors): > > > [...] > > > > DESC_WRAP - driver uses this field to detect descriptor change by device. > > Driver uses this field to detect change of wrap-around boundary by device? > > By using this, driver doesn't need to maintain any internal wrap-around count, but being aware of wrap-around by DESC_WRAP flag. > > > Thanks, > Steve So v2 simply said descriptor has a single bit: driver writes 1 there, device writes 0. This requires device to overwrite each descriptor and people asked for a way to communicate where some descriptors are not overwritten. This new bit helps device distinguish new and old descriptors written by driver. > > > [...] > > > > --- > > > > Note: should this proposal be accepted and approved, one or more > > claims disclosed to the TC admin and listed on the Virtio TC > > IPR page https://www.oasis-open.org/committees/virtio/ipr.php > > might become Essential Claims. > > Note: the page above is unfortunately out of date and out of > > my hands. I'm in the process of updating ipr disclosures > > in github instead. Will make sure all is in place before > > this proposal is put to vote. As usual this TC operates under the > > Non-Assertion Mode of the OASIS IPR Policy, which protects > > anyone implementing the virtio spec. > > > > -- > > MST > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: virtio-dev-unsubscribe at lists.oasis-open.org > > For additional commands, e-mail: virtio-dev-help at lists.oasis-open.org --------------------------------------------------------------------- To unsubscribe, e-mail: virtio-dev-unsubscribe at lists.oasis-open.org For additional commands, e-mail: virtio-dev-help at lists.oasis-open.org
Get it now. Please correct me if I missing something. Flags status hints, - DESC_DRIVER only: driver owns the descriptor w/o available info ready for device to use - DESC_DRIVER | DESC_WRAP: driver has prepared an available descriptor, device hasn't used it yet - None: device has used the descriptor, and write descriptor out - DESC_WRAP only: shall not happen, device make sure to clear it Polling behavior is, - Device monitor DESC_WRAP bit set or not; If set, go to use descriptor and clear DESC_DRIVER bit in the end (note: always need to clear DESC_WRAP) - Driver monitor DESC_DRIVER bit cleared or not; If cleared, reclaim descriptor(set DESC_DRIVER) and set DESC_WRAP once new available descriptor get ready to go -- Steve> -----Original Message----- > From: Michael S. Tsirkin [mailto:mst at redhat.com] > Sent: Thursday, September 28, 2017 7:49 AM > To: Steven Luong (sluong) > Cc: Liang, Cunming; virtio-dev at lists.oasis-open.org; > virtualization at lists.linux-foundation.org > Subject: Re: [virtio-dev] packed ring layout proposal v3 > > On Tue, Sep 26, 2017 at 11:38:18PM +0000, Steven Luong (sluong) wrote: > > Michael, > > > > Would you please give an example or two how these two flags > DESC_DRIVER and DESC_WRAP are used together? Like others, I am > confused by the description and still don?t quite grok it. > > > > Steven > > My bad, I will need to work on it. Here is an example: > > Let's assume device promised to consume packets in order > > ring size = 2 > > Ring is 0 initialized. > > Device initially polls DESC[0].flags for WRAP bit to change. > > driver adds: > > DESC[0].addr = 1234 > DESC[0].id = 0 > DESC[0].flags = DESC_DRIVER | DESC_NEXT | DESC_WRAP > > and > > DESC[0].addr = 5678 > DESC[1].id = 1 > DESC[1].flags = DESC_DRIVER | DESC_WRAP > > > it now starts polling DESC[0] flags. > > > Device reads 1234, executes it, does not use it. > > Device reads 5678, executes it, and uses it: > > DESC[0].id = 1 > DESC[0].flags = 0 > > Device now polls DESC[0].flags for WRAP bit to change. > > Now driver sees that DRIVER bit has been cleared, so it nows that id is valid. I > sees id 1, therefore id 0 and 1 has been read and are safe to overwrite. > > So it writes it out. It wrapped around to beginning of ring, so it flips the > WRAP bit to 0 on all descriptors now: > > DESC[0].addr = 9ABC > DESC[0].id = 0 > DESC[0].flags = DESC_DRIVER | DESC_NEXT > > > DESC[0].addr = DEF0 > DESC[0].id = 1 > DESC[0].flags = DESC_DRIVER > > > Next round wrap will be 1 again. > > > To summarise: > > DRIVER bit is used by driver to detect device has used one or more > descriptors. WRAP is is used by device to detect driver has made a new > descriptor available. > > > -- > MST
On Thu, Sep 28, 2017 at 02:49:15AM +0300, Michael S. Tsirkin wrote:> On Tue, Sep 26, 2017 at 11:38:18PM +0000, Steven Luong (sluong) wrote: > > Michael, > > > > Would you please give an example or two how these two flags DESC_DRIVER and DESC_WRAP are used together? Like others, I am confused by the description and still don?t quite grok it. > > > > StevenNote: I made a mistake in the email. Instead of DESC_NEXT it should read DESC_MORE everywhere. I corrected the quoted text below for simplicity.> My bad, I will need to work on it. Here is an example: > > Let's assume device promised to consume packets in order > > ring size = 2 > > Ring is 0 initialized. > > Device initially polls DESC[0].flags for WRAP bit to change. > > driver adds: > > DESC[0].addr = 1234 > DESC[0].id = 0 > DESC[0].flags = DESC_DRIVER | DESC_MORE | DESC_WRAP > > and > > DESC[0].addr = 5678 > DESC[1].id = 1 > DESC[1].flags = DESC_DRIVER | DESC_WRAP > > > it now starts polling DESC[0] flags. > > > Device reads 1234, executes it, does not use it. > > Device reads 5678, executes it, and uses it: > > DESC[0].id = 1 > DESC[0].flags = 0 > > Device now polls DESC[0].flags for WRAP bit to change. > > Now driver sees that DRIVER bit has been cleared, so it nows that id is > valid. I sees id 1, therefore id 0 and 1 has been read and are safe to > overwrite. > > So it writes it out. It wrapped around to beginning of ring, > so it flips the WRAP bit to 0 on all descriptors now: > > DESC[0].addr = 9ABC > DESC[0].id = 0 > DESC[0].flags = DESC_DRIVER | DESC_MORE > > > DESC[0].addr = DEF0 > DESC[0].id = 1 > DESC[0].flags = DESC_DRIVER > > > Next round wrap will be 1 again. > > > To summarise: > > DRIVER bit is used by driver to detect device has used one or more > descriptors. WRAP is is used by device to detect driver has made a > new descriptor available. > > > -- > MST