linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Zanussi <zanussi@us.ibm.com>
To: "Perez-Gonzalez, Inaky" <inaky.perez-gonzalez@intel.com>
Cc: "'Tom Zanussi'" <zanussi@us.ibm.com>,
	"'karim@opersys.com'" <karim@opersys.com>,
	"'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: RE: [patch] printk subsystems
Date: Tue, 22 Apr 2003 22:58:21 -0500	[thread overview]
Message-ID: <16038.3933.389383.172250@lepton.softprops.com> (raw)
In-Reply-To: <A46BBDB345A7D5118EC90002A5072C780C263B3E@orsmsx116.jf.intel.com>

Perez-Gonzalez, Inaky writes:
 > 
 > > From: Tom Zanussi [mailto:zanussi@us.ibm.com]
 > > Perez-Gonzalez, Inaky writes:
 > >  > > From: Tom Zanussi [mailto:zanussi@us.ibm.com]
 > >  > >
 > >  > > In relayfs, the event can be generated directly into the space
 > >  > > reserved for it - in fact this is exactly what LTT does.  There
 > aren't
 > >  > > two separate steps, one 'generating' the event and another copying it
 > >  > > to the relayfs buffer, if that's what you mean.
 > >  >
 > >  > In this case, what happens if the user space, through mmap, copies
 > >  > while the message is half-baked (ie, from another CPU) ... won't it
 > >  > be inconsistent?
 > > 
 > > There's a count kept, per sub-buffer, that's updated after each write.
 > > If this count doesn't match the expected size of the sub-buffer, the
 > > reader can ignore the incomplete buffer and come back to it later.
 > > The count is maintained automatically by relay_write(); if you're
 > > writing directly into the channel as LTT does though, part of the task
 > > is to call relay_commit() after the write, which updates the count and
 > > maintains consistency.
 > 
 > Hmmm, scratch, scratch ... there is something I still don't get here. 
 > I am in lockless_commit() - for what you say, and what I read, I would 
 > then expect the length of the sub-buffer would be mapped to user space, 
 > so I can memcpy out of the mmaped area and then take only the part that
 > is guaranteed to be consistent. But the atomic_add() is done on the 
 > rchan->scheme.lockless.fillcount[buffer_number]. So, I don't see how
 > that count pops out to user space, as rchan->buf to rchan->buf + rchan->
 > alloc_size is what is mapped, and rchan is a kernel-only struct that
 > is not exposed through mmap().
 > 

It 'pops' out to user space through some protocol defined between a
relayfs kernel client and the user space program.  relayfs doesn't say
anything about the protocol, but does provide the kernel client enough
information about the state of the channel via relay_info(), which
supplies among other things (these aren't the real names, they're
changed here to make things maybe a little clearer):

n_subbufs - number of sub-buffers
subbuf_size - size of each sub-bufer
subbuf_complete[] - array of booleans basically the result of 
		  fillcount[subbuf_no] == subbuf_size
subbufs_produced - by the channel
subbufs_consumed - by userspace client, maybe

This is enough information for a userspace client to figure out what
to log.  How it gets there and when is up to the client.  For
instance, the kernel client could send a signal whenever a sub-buffer
is full (which it's notified of, if it chooses to be, by a delivery
callback).  The user client could then do something like

buf = mmap(fd, n_bufs * bufsize); /* whole channel is mapped */ 

sighandler()
{
	get_channel_info_from_kernel(&info); /* ioctl/procfs/sysfs/... */
	subbufs_ready = subbufs_produced - subbufs_consumed;
	for(i=0; i<subbufs_ready; i++) {
		 subbuf_no = (subbufs_consumed + i) % n_subbufs;
		 if(!buffer_complete[subbuf_no])
			break; /* Try again next sig */
		 write(log_fd, buf + subbufno * subbuf_size, subbuf_size);
	 }
}

 > And then, once I have this, next time I read I don't want to read
 > what I already did; I guess I can advance my buf pointer to 
 > buf+real_size, but then how do I wrap around - meaning, how do I
 > detect when do I have to wrap?
 > 

Wrapping is taken care of automatically in the above code.

-- 
Regards,

Tom Zanussi <zanussi@us.ibm.com>
IBM Linux Technology Center/RAS


  reply	other threads:[~2003-04-23  3:47 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-22 22:53 [patch] printk subsystems Perez-Gonzalez, Inaky
2003-04-23  3:58 ` Tom Zanussi [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-04-24 18:56 Manfred Spraul
2003-04-24 19:10 ` bob
2003-04-23  0:28 Perez-Gonzalez, Inaky
2003-04-22 19:02 Perez-Gonzalez, Inaky
2003-04-22 19:03 ` H. Peter Anvin
2003-04-22 21:52 ` Tom Zanussi
2003-04-22 18:46 Perez-Gonzalez, Inaky
2003-04-22 23:28 ` Karim Yaghmour
2003-04-22  5:09 Perez-Gonzalez, Inaky
2003-04-24 18:22 ` bob
2003-04-22  4:02 Perez-Gonzalez, Inaky
2003-04-22  5:52 ` Karim Yaghmour
2003-04-22  6:04 ` Tom Zanussi
2003-04-22  3:04 Perez-Gonzalez, Inaky
2003-04-22  6:00 ` Tom Zanussi
2003-04-22  2:49 Perez-Gonzalez, Inaky
2003-04-22  4:34 ` Karim Yaghmour
2003-04-21 18:42 Perez-Gonzalez, Inaky
2003-04-21 18:23 Perez-Gonzalez, Inaky
2003-04-21 18:30 ` H. Peter Anvin
2003-04-17 19:58 Perez-Gonzalez, Inaky
2003-04-17 20:34 ` Karim Yaghmour
2003-04-17 21:03   ` Perez-Gonzalez, Inaky
2003-04-17 21:37     ` Tom Zanussi
2003-04-18  7:21     ` Tom Zanussi
2003-04-18  7:42     ` Greg KH
2003-04-21 15:56     ` Karim Yaghmour
2003-04-08 23:15 Chuck Ebbert
2003-04-07 20:13 Martin Hicks
2003-04-08 18:41 ` Pavel Machek
2003-04-08 20:02   ` Jes Sorensen
2003-04-08 21:02     ` Pavel Machek
2003-04-08 21:10       ` H. Peter Anvin
2003-04-08 21:57         ` Pavel Machek
2003-04-08 22:02           ` Jes Sorensen
2003-04-08 22:05           ` H. Peter Anvin
2003-04-08 22:55             ` Martin Hicks
2003-04-08 23:10               ` Randy.Dunlap
2003-04-14 18:33                 ` Patrick Mochel
2003-04-14 22:33                   ` Daniel Stekloff
2003-04-16 18:42                     ` Patrick Mochel
2003-04-16 12:35                       ` Daniel Stekloff
2003-04-16 19:16                       ` Martin Hicks
2003-04-16 12:43                         ` Daniel Stekloff
2003-04-17 15:56                           ` Martin Hicks
2003-04-17 13:58                             ` Karim Yaghmour
2003-04-15 13:27                   ` Martin Hicks
2003-04-15 14:40                     ` Karim Yaghmour
2003-04-08 22:00       ` Jes Sorensen
2003-04-11 19:21 ` Martin Hicks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16038.3933.389383.172250@lepton.softprops.com \
    --to=zanussi@us.ibm.com \
    --cc=inaky.perez-gonzalez@intel.com \
    --cc=karim@opersys.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).