From: Jim Nelson <james4765@verizon.net>
To: linux-kernel@vger.kernel.org
Subject: A general question on SMP-safe driver code.
Date: Fri, 24 Dec 2004 17:58:50 -0500 [thread overview]
Message-ID: <41CC9F2A.9080905@verizon.net> (raw)
Looking at a few older drivers, I'm trying to figure out the best ways to handle
some locking. Using drivers/char/esp.c as an example (since it's the one I'm
trying to grok right now), here is one example:
static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
{
struct esp_struct *info = (struct esp_struct *)tty->driver_data;
unsigned long orig_jiffies, char_time;
unsigned long flags;
if (serial_paranoia_check(info, tty->name, "rs_wait_until_sent"))
return;
orig_jiffies = jiffies;
char_time = ((info->timeout - HZ / 50) / 1024) / 5;
if (!char_time)
char_time = 1;
save_flags(flags); cli();
serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||
(serial_in(info, UART_ESI_STAT2) != 0xff)) {
msleep_interruptible(jiffies_to_msecs(char_time));
if (signal_pending(current))
break;
if (timeout && time_after(jiffies, orig_jiffies + timeout))
break;
serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
}
restore_flags(flags);
set_current_state(TASK_RUNNING);
}
Now, it seems like the cli()/sti() pair is to prevent other code from interrupting
the whole sequence. It looks like the only things actually need interrupts
disabled (from a command sequencing perspective) is the serial_out pairs, but you
want to keep other parts of the driver from sending other commands to the board.
So, would:
down_interruptible(&info->sem);
spin_lock_irq(&info->esp_lock);
serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
spin_unlock_irq(&info->esp_lock);
while ((serial_in(info, UART_ESI_STAT1) != 0x03) ||
(serial_in(info, UART_ESI_STAT2) != 0xff)) {
msleep_interruptible(jiffies_to_msecs(char_time));
if (signal_pending(current))
break;
if (timeout && time_after(jiffies, orig_jiffies + timeout))
break;
spin_lock_irq(&info->esp_lock);
serial_out(info, UART_ESI_CMD1, ESI_NO_COMMAND);
serial_out(info, UART_ESI_CMD1, ESI_GET_TX_AVAIL);
spin_unlock_irq(&info->esp_lock);
up(&info->esp_sem);
work if all other areas of the driver that send commands to the board also try for
the semaphore?
Is there an easier way of doing this?
Jim
next reply other threads:[~2004-12-24 22:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-12-24 22:58 Jim Nelson [this message]
2004-12-24 23:28 ` Linus Torvalds
2004-12-25 12:23 ` Alan Cox
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=41CC9F2A.9080905@verizon.net \
--to=james4765@verizon.net \
--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
Powered by JetHome