Hi, there is a macro in io/ring.h as follows: 211#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ \ | 212 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \ 213 unsigned int rsp = RING_SIZE(_r) - \ 214 ((_r)->req_cons - (_r)->rsp_prod_pvt); \ 215 req < rsp ? req : rsp; \ 216}) Anyone could explain this? _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
2013-Apr-08 13:32 UTC
Re: [Problem] about src/xen/include/public/io/ring.h
On Mon, Apr 08, 2013 at 04:10:49PM +0800, 马磊 wrote:> Hi, > there is a macro in io/ring.h as follows: > > 211#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ > \ | > 212 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; > \ > 213 unsigned int rsp = RING_SIZE(_r) - > \ > 214 ((_r)->req_cons - (_r)->rsp_prod_pvt); > \ > 215 req < rsp ? req : rsp; > \ > 216}) > > Anyone could explain this?Which part are you unclear about? I might be easier if you deconstruct the macro and write out inthe code. That should give you an idea of what it does. <hint: Figure out first what RING_SIZE comes out to>> _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xen.org > http://lists.xen.org/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Mon, Apr 8, 2013 at 9:32 PM, Konrad Rzeszutek Wilk < konrad.wilk@oracle.com> wrote:> On Mon, Apr 08, 2013 at 04:10:49PM +0800, 马磊 wrote: > > Hi, > > there is a macro in io/ring.h as follows: > > > > 211#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ > > \ | > > 212 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; > > \ > > 213 unsigned int rsp = RING_SIZE(_r) - > > \ > > 214 ((_r)->req_cons - (_r)->rsp_prod_pvt); > > \ > > 215 req < rsp ? req : rsp; > > \ > > 216}) > > > > Anyone could explain this? > > Which part are you unclear about? > > I might be easier if you deconstruct the macro and write out > inthe code. That should give you an idea of what it does. > <hint: Figure out first what RING_SIZE comes out to> > > > _______________________________________________ > > Xen-devel mailing list > > Xen-devel@lists.xen.org > > http://lists.xen.org/xen-devel > >Why does the macro for response is : 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) why not the macro for request written like this: #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ ((_r)->sring->req_prod - (_r)->req_cons) The RING_SIZE means the maximum number for the shared ring to accommodate the req/resp message struct, is that? _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
reference:xen-src/docs/misc/blkif-drivers-explained.txt : 229-245 lines _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
2013-Apr-10 13:15 UTC
Re: [Problem] about src/xen/include/public/io/ring.h
On Tue, Apr 09, 2013 at 11:05:52AM +0800, 马磊 wrote:> On Mon, Apr 8, 2013 at 9:32 PM, Konrad Rzeszutek Wilk < > konrad.wilk@oracle.com> wrote: > > > On Mon, Apr 08, 2013 at 04:10:49PM +0800, 马磊 wrote: > > > Hi, > > > there is a macro in io/ring.h as follows: > > > > > > 211#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ > > > \ | > > > 212 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; > > > \ > > > 213 unsigned int rsp = RING_SIZE(_r) - > > > \ > > > 214 ((_r)->req_cons - (_r)->rsp_prod_pvt); > > > \ > > > 215 req < rsp ? req : rsp; > > > \ > > > 216}) > > > > > > Anyone could explain this? > > > > Which part are you unclear about? > > > > I might be easier if you deconstruct the macro and write out > > inthe code. That should give you an idea of what it does. > > <hint: Figure out first what RING_SIZE comes out to> > > > > > _______________________________________________ > > > Xen-devel mailing list > > > Xen-devel@lists.xen.org > > > http://lists.xen.org/xen-devel > > > > > Why does the macro for response is : > 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ > 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) > > why not the macro for request written like this: > #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ > ((_r)->sring->req_prod - (_r)->req_cons) > > > The RING_SIZE means the maximum number for the shared ring to accommodate > the req/resp message struct, is that?Correct. The req message is about 112 bytes, and at the start of the ring you have 64-bytes for rsp, req, etc. So the end result is 32 ring entries. The response structures are much smaller, but since you are sharing the ring (so you put both requests and responses on it), it is still limited to 32 entries. I am not really sure what you mean by 'why not the macro'. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
2013-Apr-10 13:15 UTC
Re: [Problem] about src/xen/include/public/io/ring.h
On Wed, Apr 10, 2013 at 02:20:12PM +0800, 马磊 wrote:> reference:xen-src/docs/misc/blkif-drivers-explained.txt : 229-245 linesDoes that mean it answers your question? _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
I means, in ring.h, The macro for unconsumed response is : 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) \ 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) *Should the macro for unconsumed request be written like this:* #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ ((_r)->sring->req_prod - (_r)->req_cons) On Wed, Apr 10, 2013 at 9:15 PM, Konrad Rzeszutek Wilk < konrad.wilk@oracle.com> wrote:> On Tue, Apr 09, 2013 at 11:05:52AM +0800, 马磊 wrote: > > On Mon, Apr 8, 2013 at 9:32 PM, Konrad Rzeszutek Wilk < > > konrad.wilk@oracle.com> wrote: > > > > > On Mon, Apr 08, 2013 at 04:10:49PM +0800, 马磊 wrote: > > > > Hi, > > > > there is a macro in io/ring.h as follows: > > > > > > > > 211#define RING_HAS_UNCONSUMED_REQUESTS(_r) ({ > > > > \ | > > > > 212 unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; > > > > \ > > > > 213 unsigned int rsp = RING_SIZE(_r) - > > > > \ > > > > 214 ((_r)->req_cons - (_r)->rsp_prod_pvt); > > > > \ > > > > 215 req < rsp ? req : rsp; > > > > \ > > > > 216}) > > > > > > > > Anyone could explain this? > > > > > > Which part are you unclear about? > > > > > > I might be easier if you deconstruct the macro and write out > > > inthe code. That should give you an idea of what it does. > > > <hint: Figure out first what RING_SIZE comes out to> > > > > > > > _______________________________________________ > > > > Xen-devel mailing list > > > > Xen-devel@lists.xen.org > > > > http://lists.xen.org/xen-devel > > > > > > > > Why does the macro for response is : > > 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) > \ > > 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) > > > > why not the macro for request written like this: > > #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ > > ((_r)->sring->req_prod - (_r)->req_cons) > > > > > > The RING_SIZE means the maximum number for the shared ring to accommodate > > the req/resp message struct, is that? > > Correct. The req message is about 112 bytes, and at the start of the ring > you have 64-bytes for rsp, req, etc. So the end result is 32 ring entries. > > The response structures are much smaller, but since you are sharing the > ring > (so you put both requests and responses on it), it is still limited to 32 > entries. > > I am not really sure what you mean by ''why not the macro''. >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
2013-Apr-11 13:20 UTC
Re: [Problem] about src/xen/include/public/io/ring.h
On Thu, Apr 11, 2013 at 03:46:25PM +0800, 马磊 wrote:> I means, in ring.h, > The macro for unconsumed response is : > 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) > \ > 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) > > *Should the macro for unconsumed request be written like this:* > #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ > ((_r)->sring->req_prod - (_r)->req_cons) >Please don't top post. It is close to that in the code: #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ ({ \ unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \ unsigned int rsp = RING_SIZE(_r) - \ ((_r)->req_cons - (_r)->rsp_prod_pvt); \ req < rsp ? req : rsp; \ }) Can you figure out why it has the check against resp_cons and rsp_prod_pvt ? _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Thu, Apr 11, 2013 at 9:20 PM, Konrad Rzeszutek Wilk < konrad.wilk@oracle.com> wrote:> On Thu, Apr 11, 2013 at 03:46:25PM +0800, 马磊 wrote: > > I means, in ring.h, > > The macro for unconsumed response is : > > 207#define RING_HAS_UNCONSUMED_RESPONSES(_r) > > \ > > 208 ((_r)->sring->rsp_prod - (_r)->rsp_cons) > > > > *Should the macro for unconsumed request be written like this:* > > #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ > > ((_r)->sring->req_prod - (_r)->req_cons) > > > > Please don''t top post. > > It is close to that in the code: > > #define RING_HAS_UNCONSUMED_REQUESTS(_r) \ > ({ \ > unsigned int req = (_r)->sring->req_prod - (_r)->req_cons; \ > unsigned int rsp = RING_SIZE(_r) - \ > ((_r)->req_cons - (_r)->rsp_prod_pvt); \ > req < rsp ? req : rsp; \ > }) > > Can you figure out why it has the check against resp_cons and rsp_prod_pvt > ? >Assume* X = (_r)->req_cons - (_r)->rsp_prod_pvt* and *Y = number of free ring buffers for responder(backend driver)*, they are equal in amount, is that? Then rsp = RING_SIZE(r) - (X - Y), I can''t figure out this and the return value ` req < rsp ? req : rsp` ? _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Fri, 2013-04-12 at 03:21 +0100, 马磊 wrote:> On Thu, Apr 11, 2013 at 9:20 PM, Konrad Rzeszutek Wilk > <konrad.wilk@oracle.com> wrote:> Please don't top post.马磊, Can you also stop posting HTML mails, thanks.> Then rsp = RING_SIZE(r) - (X - Y), I can't figure out this and the > return value ` req < rsp ? req : rsp` ?Perhaps think about the case when the ring becomes full of either responses or requests and what that means in terms of "wrapping" in the ring. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Fri, Apr 12, 2013 at 3:49 PM, Ian Campbell <Ian.Campbell@citrix.com>wrote:> On Fri, 2013-04-12 at 03:21 +0100, 马磊 wrote: > > > > On Thu, Apr 11, 2013 at 9:20 PM, Konrad Rzeszutek Wilk > > <konrad.wilk@oracle.com> wrote: > > > Please don''t top post. > > 马磊, Can you also stop posting HTML mails, thanks. >I use the gmail client, reply through clicking `reply to all` in the input text frame at bottom of the html page, and then send it away. Do you mean to not to copy too many long time ago message?> > Then rsp = RING_SIZE(r) - (X - Y), I can''t figure out this and the > > return value ` req < rsp ? req : rsp` ? > > Perhaps think about the case when the ring becomes full of either > responses or requests and what that means in terms of "wrapping" in the > ring. > > Ian. > >It''s difficult for me to image the ring buffer scene where the ring becomes full of either responses or requests , because the src/docs/misc/blkif-drivers-explained.txt mentioned that a ring is partitioned into a request and a response region by four pointers and pointers may only advance, and may not pass one another. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Fri, 2013-04-12 at 11:35 +0100, 马磊 wrote:> It's difficult for me to image the ring buffer scene where the ring > becomes full of either > responses or requests , because the > src/docs/misc/blkif-drivers-explained.txt mentionedI can't find a copy of this document.> that > a ring is partitioned into a request and a response region by four > pointers and pointers may only > advance, and may not pass one another.Correct, although the ring is only partitioned by the pointers and their current values, it is not statically partitioned into those two halves or anything like that. This stuff is quite difficult to describe in words. Perhaps you would find it helpful to draw the ring and the 4 pointers and to consider what happens when each pointer catches up to (but doesn't pass) the one in front, and what this tells you about the number of requests/responses which are on the ring at that time. Then remember that the ring is actually represented as a single page of memory, with the pointers logically wrapping from +4096 (==PAGE_SIZE) back to +0. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
> > This stuff is quite difficult to describe in words. Perhaps you would > find it helpful to draw the ring and the 4 pointers and to consider what > happens when each pointer catches up to (but doesn''t pass) the one in > front, and what this tells you about the number of requests/responses > which are on the ring at that time. > >Could you show me a rough figure for describing unconsumed requests in a specific scene.> Then remember that the ring is actually represented as a single page of > memory, with the pointers logically wrapping from +4096 (==PAGE_SIZE) > back to +0. > > Ian. > >You mean the ring is a circle buffer except for the ring header. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
Konrad Rzeszutek Wilk
2013-Apr-12 13:45 UTC
Re: [Problem] about src/xen/include/public/io/ring.h
On Fri, Apr 12, 2013 at 07:24:52PM +0800, 马磊 wrote:> > > > This stuff is quite difficult to describe in words. Perhaps you would > > find it helpful to draw the ring and the 4 pointers and to consider what > > happens when each pointer catches up to (but doesn't pass) the one in > > front, and what this tells you about the number of requests/responses > > which are on the ring at that time. > > > > > Could you show me a rough figure for describing unconsumed requests in a > specific scene.It would be easier if you just instrumented the code in question to see how it works.> > > > Then remember that the ring is actually represented as a single page of > > memory, with the pointers logically wrapping from +4096 (==PAGE_SIZE) > > back to +0. > > > > Ian. > > > > > You mean the ring is a circle buffer except for the ring header._______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel
On Fri, Apr 12, 2013 at 9:45 PM, Konrad Rzeszutek Wilk < konrad.wilk@oracle.com> wrote:> On Fri, Apr 12, 2013 at 07:24:52PM +0800, 马磊 wrote: > > > > > > This stuff is quite difficult to describe in words. Perhaps you would > > > find it helpful to draw the ring and the 4 pointers and to consider > what > > > happens when each pointer catches up to (but doesn''t pass) the one in > > > front, and what this tells you about the number of requests/responses > > > which are on the ring at that time. > > > > > > > > Could you show me a rough figure for describing unconsumed requests in a > > specific scene. > > It would be easier if you just instrumented the code in question to see > how it works. > >Could you show me a scene in which what value the four pointers are respectively equal to? That''s intuitional. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel