All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Linas Vepstas <linas@austin.ibm.com>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org
Subject: Re: [PATCH] kernel/printk.c  lockless access
Date: Thu, 6 Jan 2005 16:12:41 -0800	[thread overview]
Message-ID: <20050106161241.11a8d07c.akpm@osdl.org> (raw)
In-Reply-To: <20050106195812.GL22274@austin.ibm.com>

Linas Vepstas <linas@austin.ibm.com> wrote:
>
> I was wondering if you could see your way to accepting the attached
> patch, which provides access to the syslog buffer pointers.
> 
> The basic idea is that if a system has crashed, it can be handy to
> be able to view the contents of the syslog buffer.  Unfortunately,
> this is currently hard to do.
> 
>  --  char __log_buf[] is declared static in printk.c, so it cannot
>      be found in the ksyms table.
> 
>  -- do_syslog() uses spinlocks to protect the data structure, and
>     so will typically deadlock if called.
> 
> The 'fix' is to provide a routine that simply returns the pointers
> to the log buffer.  
> 
> I'd be thrilled to have this patch accepted ... 

We faced the same problem in the Digeo kernel.  When the kernel oopses we
want to grab the last kilobyte or so of the printk buffer and stash it into
nvram.  We did this via a function which copies the data rather than
exporting all those variables, which I think is a nicer and more
maintainable approach:

/** get_printk_state - read the printk log buffer state
 *
 * @how_far_back: how many bytes back-in-time to look
 *
 * get_printk_state() gives the caller the current printk
 * log buffer head index, for later use by get_printk_buffer()
 * The index is offset by @how_far_back, which allows the caller
 * to look at previously-emitted information.  Negative values of
 * how_far_back don't make sense.
 */
int get_printk_state(int how_far_back)
{
	return (log_end - how_far_back) & LOG_BUF_MASK;
}

/** get_printk_buffer - read bytes from the printk buffer
 *
 * get_printk_buffer() will copy some bytes from the printk
 * ring buffer into the caller's buffer.
 *
 * @buf - the caller's buffer.  Bytes are written here.
 * @len - the amount of space at *@buf
 * @start_at - where in the log buffer to start copying out
 * data.  Presumably from a previous get_printk_state() call.
 *
 * get_printk_buffer() does not place a null at the end of *@buf
 *
 * get_printk_state() returns the number of bytes which it wrote
 * to *@buf.
 */
int get_printk_buffer(char *buf, int len, int start_at)
{
	int count;
	int at = start_at;

	for (count = 0; count < len; count++, at++) {
		if ((at & LOG_BUF_MASK) == (log_end & LOG_BUF_MASK))
			break;
		buf[count] = LOG_BUF(at);
	}
	return count;
}

(all available in a horrendous tarball at
http://www.digeo.com/assets/datasheets/digeo-mc1-2.0.8-mods.tar.bz2)

You want to cook up something like that?  (That's 2.4 code, and might need
work for 2.6 changes).



  parent reply	other threads:[~2005-01-07  0:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-06 19:58 [PATCH] kernel/printk.c lockless access Linas Vepstas
2005-01-06 20:50 ` Andi Kleen
2005-01-07  0:12 ` Andrew Morton [this message]
2005-01-07  0:26   ` Anton Blanchard
2005-01-07  0:25     ` Randy.Dunlap
2005-01-07  1:54       ` Alan Cox
2005-01-09 10:44         ` Frank van Maarseveen
2005-01-09 22:31           ` David Wagner
2005-01-09 23:00           ` Alan Cox
2005-01-10 20:43             ` Matt Mackall
2005-01-08  2:37 ` Keith Owens

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=20050106161241.11a8d07c.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=linas@austin.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.