Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 May 2001 16:31:21 +0900
From:      Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>
To:        current@FreeBSD.org
Cc:        Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>
Subject:   Lock of struct filedesc, file, pgrp, session and sigio
Message-ID:  <200105310731.f4V7VLD29187@rina.r.dl.itc.u-tokyo.ac.jp>

next in thread | raw e-mail | index | archive | help
Lock of struct filedesc, file, pgrp, session and sigio is now ready
for testing.

The patch is at

http://people.FreeBSD.org/~tanimura/patches/fd_pgrp.diff.gz

Below is the brief description of locking.


1. struct filedesc and struct file

- fd_mtx protects struct filedesc.

- f_mtx protects struct file. Refer to sys/file.h for detail.

- Do not look up a file descriptor table directly but use FFIND*
  macros defined in sys/filedesc.h. They handle locking a file
  descriptor table and a file descriptor.

- getvnode() locks a file descriptor.

- p_fd may change during the life of a process if it is sharing its
  file descriptor table when the process calls execve(2). As nobody
  except curproc and the parent process in fork1() touches the file
  descriptor table of a process, the lock type of p_fd should be "(a)
  only touched by curproc or parent during fork/wait."


2. struct proc, struct pgrp and struct session

- pgrphash_lock and pg_mtx protects struct pgrp. Refer to sys/proc.h
  for detail.

- s_mtx protects struct session. Refer to sys/proc.h for detail.

- Introduce p_pgrpmtx to protect p_pgrp of struct proc in cooperation
  with p_mtx. This allows locking of a process in a process group
  without lock order reversal. The lock order of them is shown below.

  1st: p_pgrpmtx
  2st: pg_mtx
  3rd: p_mtx

- You may lock more than one process groups provided that they belong
  to an identical session and you lock the session in advance.

- psignal() requires the lock of the process group to which a
  destination process belongs if the property of a signal includes
  SA_STOP. PROC_LOCK_PSIGNAL() and PROC_UNLOCK_PSIGNAL() handle
  those lock and unlock.

  TODO: Pass a signal to PROC_(UN)LOCK_PSIGNAL() to avoid unnecessary
  lock.

- pgsignal() requires the lock of a destination process group.


3. struct sigio

- struct sigio forms a list(struct sigiolst), residing in a process or
  a process group. p_mtx of a process or pg_mtx of a process group is
  responsible to lock struct sigiolst. The members of struct sigio
  other than sio_pgsigio never change.

- A macro FUNSETOWN locks the list of struct sigio, calls funsetown()
  and unlocks the list.

-- 
Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp> <tanimura@FreeBSD.org>

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200105310731.f4V7VLD29187>