Commit aad26f55 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'docs-6.0' of git://git.lwn.net/linux

Pull documentation updates from Jonathan Corbet:
 "This was a moderately busy cycle for documentation, but nothing
  all that earth-shaking:

   - More Chinese translations, and an update to the Italian
     translations.

     The Japanese, Korean, and traditional Chinese translations
     are more-or-less unmaintained at this point, instead.

   - Some build-system performance improvements.

   - The removal of the archaic submitting-drivers.rst document,
     with the movement of what useful material that remained into
     other docs.

   - Improvements to sphinx-pre-install to, hopefully, give more
     useful suggestions.

   - A number of build-warning fixes

  Plus the usual collection of typo fixes, updates, and more"

* tag 'docs-6.0' of git://git.lwn.net/linux: (92 commits)
  docs: efi-stub: Fix paths for x86 / arm stubs
  Docs/zh_CN: Update the translation of sched-stats to 5.19-rc8
  Docs/zh_CN: Update the translation of pci to 5.19-rc8
  Docs/zh_CN: Update the translation of pci-iov-howto to 5.19-rc8
  Docs/zh_CN: Update the translation of usage to 5.19-rc8
  Docs/zh_CN: Update the translation of testing-overview to 5.19-rc8
  Docs/zh_CN: Update the translation of sparse to 5.19-rc8
  Docs/zh_CN: Update the translation of kasan to 5.19-rc8
  Docs/zh_CN: Update the translation of iio_configfs to 5.19-rc8
  doc:it_IT: align Italian documentation
  docs: Remove spurious tag from admin-guide/mm/overcommit-accounting.rst
  Documentation: process: Update email client instructions for Thunderbird
  docs: ABI: correct QEMU fw_cfg spec path
  doc/zh_CN: remove submitting-driver reference from docs
  docs: zh_TW: align to submitting-drivers removal
  docs: zh_CN: align to submitting-drivers removal
  docs: ko_KR: howto: remove reference to removed submitting-drivers
  docs: ja_JP: howto: remove reference to removed submitting-drivers
  docs: it_IT: align to submitting-drivers removal
  docs: process: remove outdated submitting-drivers.rst
  ...
parents b0691222 339170d8
......@@ -12,8 +12,9 @@ Description:
configuration data to the guest userspace.
The authoritative guest-side hardware interface documentation
to the fw_cfg device can be found in "docs/specs/fw_cfg.txt"
in the QEMU source tree.
to the fw_cfg device can be found in "docs/specs/fw_cfg.rst"
in the QEMU source tree, or online at:
https://qemu-project.gitlab.io/qemu/specs/fw_cfg.html
**SysFS fw_cfg Interface**
......
config WARN_MISSING_DOCUMENTS
bool "Warn if there's a missing documentation file"
depends on COMPILE_TEST
help
......
......@@ -7,10 +7,9 @@ This list is the Linux Device List, the official registry of allocated
device numbers and ``/dev`` directory nodes for the Linux operating
system.
The LaTeX version of this document is no longer maintained, nor is
the document that used to reside at lanana.org. This version in the
mainline Linux kernel is the master document. Updates shall be sent
as patches to the kernel maintainers (see the
The version of this document at lanana.org is no longer maintained. This
version in the mainline Linux kernel is the master document. Updates
shall be sent as patches to the kernel maintainers (see the
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>` document).
Specifically explore the sections titled "CHAR and MISC DRIVERS", and
"BLOCK LAYER" in the MAINTAINERS file to find the right maintainers
......
......@@ -7,10 +7,10 @@ as a PE/COFF image, thereby convincing EFI firmware loaders to load
it as an EFI executable. The code that modifies the bzImage header,
along with the EFI-specific entry point that the firmware loader
jumps to are collectively known as the "EFI boot stub", and live in
arch/x86/boot/header.S and arch/x86/boot/compressed/eboot.c,
arch/x86/boot/header.S and drivers/firmware/efi/libstub/x86-stub.c,
respectively. For ARM the EFI stub is implemented in
arch/arm/boot/compressed/efi-header.S and
arch/arm/boot/compressed/efi-stub.c. EFI stub code that is shared
drivers/firmware/efi/libstub/arm32-stub.c. EFI stub code that is shared
between architectures is in drivers/firmware/efi/libstub.
For arm64, there is no compressed kernel support, so the Image itself
......
......@@ -3109,7 +3109,7 @@
mem_encrypt=on: Activate SME
mem_encrypt=off: Do not activate SME
Refer to Documentation/virt/kvm/amd-memory-encryption.rst
Refer to Documentation/virt/kvm/x86/amd-memory-encryption.rst
for details on when memory encryption can be activated.
mem_sleep_default= [SUSPEND] Default system suspend mode:
......
......@@ -38,8 +38,8 @@ acct
If BSD-style process accounting is enabled these values control
its behaviour. If free space on filesystem where the log lives
goes below ``lowwater``% accounting suspends. If free space gets
above ``highwater``% accounting resumes. ``frequency`` determines
goes below ``lowwater``\ % accounting suspends. If free space gets
above ``highwater``\ % accounting resumes. ``frequency`` determines
how often do we check the amount of free space (value is in
seconds). Default:
......
......@@ -171,96 +171,73 @@ HWCAP_PACG
Documentation/arm64/pointer-authentication.rst.
HWCAP2_DCPODP
Functionality implied by ID_AA64ISAR1_EL1.DPB == 0b0010.
HWCAP2_SVE2
Functionality implied by ID_AA64ZFR0_EL1.SVEVer == 0b0001.
HWCAP2_SVEAES
Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0001.
HWCAP2_SVEPMULL
Functionality implied by ID_AA64ZFR0_EL1.AES == 0b0010.
HWCAP2_SVEBITPERM
Functionality implied by ID_AA64ZFR0_EL1.BitPerm == 0b0001.
HWCAP2_SVESHA3
Functionality implied by ID_AA64ZFR0_EL1.SHA3 == 0b0001.
HWCAP2_SVESM4
Functionality implied by ID_AA64ZFR0_EL1.SM4 == 0b0001.
HWCAP2_FLAGM2
Functionality implied by ID_AA64ISAR0_EL1.TS == 0b0010.
HWCAP2_FRINT
Functionality implied by ID_AA64ISAR1_EL1.FRINTTS == 0b0001.
HWCAP2_SVEI8MM
Functionality implied by ID_AA64ZFR0_EL1.I8MM == 0b0001.
HWCAP2_SVEF32MM
Functionality implied by ID_AA64ZFR0_EL1.F32MM == 0b0001.
HWCAP2_SVEF64MM
Functionality implied by ID_AA64ZFR0_EL1.F64MM == 0b0001.
HWCAP2_SVEBF16
Functionality implied by ID_AA64ZFR0_EL1.BF16 == 0b0001.
HWCAP2_I8MM
Functionality implied by ID_AA64ISAR1_EL1.I8MM == 0b0001.
HWCAP2_BF16
Functionality implied by ID_AA64ISAR1_EL1.BF16 == 0b0001.
HWCAP2_DGH
Functionality implied by ID_AA64ISAR1_EL1.DGH == 0b0001.
HWCAP2_RNG
Functionality implied by ID_AA64ISAR0_EL1.RNDR == 0b0001.
HWCAP2_BTI
Functionality implied by ID_AA64PFR0_EL1.BT == 0b0001.
HWCAP2_MTE
Functionality implied by ID_AA64PFR1_EL1.MTE == 0b0010, as described
by Documentation/arm64/memory-tagging-extension.rst.
HWCAP2_ECV
Functionality implied by ID_AA64MMFR0_EL1.ECV == 0b0001.
HWCAP2_AFP
Functionality implied by ID_AA64MFR1_EL1.AFP == 0b0001.
HWCAP2_RPRES
Functionality implied by ID_AA64ISAR2_EL1.RPRES == 0b0001.
HWCAP2_MTE3
Functionality implied by ID_AA64PFR1_EL1.MTE == 0b0011, as described
by Documentation/arm64/memory-tagging-extension.rst.
......
......@@ -66,7 +66,7 @@ The wiki documentation always refers to the linux-next version of the script.
For Semantic Patch Language(SmPL) grammar documentation refer to:
http://coccinelle.lip6.fr/documentation.php
https://coccinelle.gitlabpages.inria.fr/website/docs/main_grammar.html
Using Coccinelle on the Linux kernel
------------------------------------
......
......@@ -208,6 +208,14 @@ In general, the rules for selftests are
Contributing new tests (details)
================================
* In your Makefile, use facilities from lib.mk by including it instead of
reinventing the wheel. Specify flags and binaries generation flags on
need basis before including lib.mk. ::
CFLAGS = $(KHDR_INCLUDES)
TEST_GEN_PROGS := close_range_test
include ../lib.mk
* Use TEST_GEN_XXX if such binaries or files are generated during
compiling.
......@@ -230,13 +238,30 @@ Contributing new tests (details)
* First use the headers inside the kernel source and/or git repo, and then the
system headers. Headers for the kernel release as opposed to headers
installed by the distro on the system should be the primary focus to be able
to find regressions.
to find regressions. Use KHDR_INCLUDES in Makefile to include headers from
the kernel source.
* If a test needs specific kernel config options enabled, add a config file in
the test directory to enable them.
e.g: tools/testing/selftests/android/config
* Create a .gitignore file inside test directory and add all generated objects
in it.
* Add new test name in TARGETS in selftests/Makefile::
TARGETS += android
* All changes should pass::
kselftest-{all,install,clean,gen_tar}
kselftest-{all,install,clean,gen_tar} O=abo_path
kselftest-{all,install,clean,gen_tar} O=rel_path
make -C tools/testing/selftests {all,install,clean,gen_tar}
make -C tools/testing/selftests {all,install,clean,gen_tar} O=abs_path
make -C tools/testing/selftests {all,install,clean,gen_tar} O=rel_path
Test Module
===========
......
......@@ -2,7 +2,7 @@
This module is part of the DA9061/DA9062/DA9063. For more details about entire
DA9062 and DA9061 chips see Documentation/devicetree/bindings/mfd/da9062.txt
For DA9063 see Documentation/devicetree/bindings/mfd/da9063.txt
For DA9063 see Documentation/devicetree/bindings/mfd/dlg,da9063.yaml
This module provides the KEY_POWER event.
......
.. title:: Kernel-doc comments
===========================
Writing kernel-doc comments
===========================
......
......@@ -132,7 +132,8 @@ format-specific subdirectories under ``Documentation/output``.
To generate documentation, Sphinx (``sphinx-build``) must obviously be
installed. For prettier HTML output, the Read the Docs Sphinx theme
(``sphinx_rtd_theme``) is used if available. For PDF output you'll also need
``XeLaTeX`` and ``convert(1)`` from ImageMagick (https://www.imagemagick.org).
``XeLaTeX`` and ``convert(1)`` from ImageMagick
(https://www.imagemagick.org).\ [#ink]_
All of these are widely available and packaged in distributions.
To pass extra options to Sphinx, you can use the ``SPHINXOPTS`` make
......@@ -150,8 +151,19 @@ If the theme is not available, it will fall-back to the classic one.
The Sphinx theme can be overridden by using the ``DOCS_THEME`` make variable.
There is another make variable ``SPHINXDIRS``, which is useful when test
building a subset of documentation. For example, you can build documents
under ``Documentation/doc-guide`` by running
``make SPHINXDIRS=doc-guide htmldocs``.
The documentation section of ``make help`` will show you the list of
subdirectories you can specify.
To remove the generated documentation, run ``make cleandocs``.
.. [#ink] Having ``inkscape(1)`` from Inkscape (https://inkscape.org)
as well would improve the quality of images embedded in PDF
documents, especially for kernel releases 5.18 and later.
Writing Documentation
=====================
......
......@@ -114,7 +114,7 @@ For a function using multiple GPIOs all of those can be obtained with one call::
This function returns a struct gpio_descs which contains an array of
descriptors. It also contains a pointer to a gpiolib private structure which,
if passed back to get/set array functions, may speed up I/O proocessing::
if passed back to get/set array functions, may speed up I/O processing::
struct gpio_descs {
struct gpio_array *info;
......
......@@ -119,7 +119,7 @@ GPIO lines with debounce support
Debouncing is a configuration set to a pin indicating that it is connected to
a mechanical switch or button, or similar that may bounce. Bouncing means the
line is pulled high/low quickly at very short intervals for mechanical
reasons. This can result in the value being unstable or irqs fireing repeatedly
reasons. This can result in the value being unstable or irqs firing repeatedly
unless the line is debounced.
Debouncing in practice involves setting up a timer when something happens on
......@@ -219,7 +219,7 @@ use a trick: when a line is set as output, if the line is flagged as open
drain, and the IN output value is low, it will be driven low as usual. But
if the IN output value is set to high, it will instead *NOT* be driven high,
instead it will be switched to input, as input mode is high impedance, thus
achieveing an "open drain emulation" of sorts: electrically the behaviour will
achieving an "open drain emulation" of sorts: electrically the behaviour will
be identical, with the exception of possible hardware glitches when switching
the mode of the line.
......@@ -642,7 +642,7 @@ In this case the typical set-up will look like this:
As you can see pretty similar, but you do not supply a parent handler for
the IRQ, instead a parent irqdomain, an fwnode for the hardware and
a funcion .child_to_parent_hwirq() that has the purpose of looking up
a function .child_to_parent_hwirq() that has the purpose of looking up
the parent hardware irq from a child (i.e. this gpio chip) hardware irq.
As always it is good to look at examples in the kernel tree for advice
on how to find the required pieces.
......
......@@ -44,7 +44,7 @@ These devices will appear on the system as ``/dev/gpiochip0`` thru
found in the kernel tree ``tools/gpio`` subdirectory.
For structured and managed applications, we recommend that you make use of the
libgpiod_ library. This provides helper abstractions, command line utlities
libgpiod_ library. This provides helper abstractions, command line utilities
and arbitration for multiple simultaneous consumers on the same GPIO chip.
.. _libgpiod: https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/
......@@ -25,8 +25,7 @@ and userspace consumers. The kernel space consumers can directly talk to HTE
subsystem while userspace consumers timestamp requests go through GPIOLIB CDEV
framework to HTE subsystem.
.. kernel-doc:: drivers/gpio/gpiolib.c
:functions: gpiod_enable_hw_timestamp_ns gpiod_disable_hw_timestamp_ns
See gpiod_enable_hw_timestamp_ns() and gpiod_disable_hw_timestamp_ns().
For userspace consumers, GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE flag must be
specified during IOCTL calls. Refer to ``tools/gpio/gpio-event-mon.c``, which
......@@ -37,7 +36,7 @@ LIC (Legacy Interrupt Controller) IRQ GTE
This GTE instance timestamps LIC IRQ lines in real time. There are 352 IRQ
lines which this instance can add timestamps to in real time. The hte
devicetree binding described at ``Documentation/devicetree/bindings/hte/``
devicetree binding described at ``Documentation/devicetree/bindings/timestamp``
provides an example of how a consumer can request an IRQ line. Since it is a
one-to-one mapping with IRQ GTE provider, consumers can simply specify the IRQ
number that they are interested in. There is no userspace consumer support for
......
......@@ -818,10 +818,11 @@ Compression implementation
Instead, the main goal is to reduce data writes to flash disk as much as
possible, resulting in extending disk life time as well as relaxing IO
congestion. Alternatively, we've added ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS)
interface to reclaim compressed space and show it to user after putting the
immutable bit. Immutable bit, after release, it doesn't allow writing/mmaping
on the file, until reserving compressed space via
ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or truncating filesize to zero.
interface to reclaim compressed space and show it to user after setting a
special flag to the inode. Once the compressed space is released, the flag
will block writing data to the file until either the compressed space is
reserved via ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) or the file size is
truncated to zero.
Compress metadata layout::
......
......@@ -607,7 +607,7 @@ can be removed.
User xattr
----------
The the "-o userxattr" mount option forces overlayfs to use the
The "-o userxattr" mount option forces overlayfs to use the
"user.overlay." xattr namespace instead of "trusted.overlay.". This is
useful for unprivileged mounting of overlayfs.
......
......@@ -12,7 +12,6 @@ increase the chances of your change being accepted.
* It should be unnecessary to mention, but please read and follow:
- Documentation/process/submit-checklist.rst
- Documentation/process/submitting-drivers.rst
- Documentation/process/submitting-patches.rst
- Documentation/process/coding-style.rst
......
......@@ -755,8 +755,7 @@ make a neat patch, there's administrative work to be done:
it implies a more-than-passing commitment to some part of the code.
- Finally, don't forget to read
``Documentation/process/submitting-patches.rst`` and possibly
``Documentation/process/submitting-drivers.rst``.
``Documentation/process/submitting-patches.rst``
Kernel Cantrips
===============
......
......@@ -10,8 +10,7 @@ of conventions and procedures which are used in the posting of patches;
following them will make life much easier for everybody involved. This
document will attempt to cover these expectations in reasonable detail;
more information can also be found in the files
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>`,
:ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
and :ref:`Documentation/process/submit-checklist.rst <submitchecklist>`.
......
......@@ -5,15 +5,13 @@ For more information
There are numerous sources of information on Linux kernel development and
related topics. First among those will always be the Documentation
directory found in the kernel source distribution. The top-level :ref:`process/howto.rst <process_howto>`
file is an important starting point; :ref:`process/submitting-patches.rst <submittingpatches>`
and :ref:`process/submitting-drivers.rst <submittingdrivers>`
are also something which all kernel developers should
read. Many internal kernel APIs are documented using the kerneldoc
mechanism; "make htmldocs" or "make pdfdocs" can be used to generate those
documents in HTML or PDF format (though the version of TeX shipped by some
distributions runs into internal limits and fails to process the documents
properly).
directory found in the kernel source distribution. Start with the
top-level :ref:`process/howto.rst <process_howto>`; also read
:ref:`process/submitting-patches.rst <submittingpatches>`. Many internal
kernel APIs are documented using the kerneldoc mechanism; "make htmldocs"
or "make pdfdocs" can be used to generate those documents in HTML or PDF
format (though the version of TeX shipped by some distributions runs into
internal limits and fails to process the documents properly).
Various web sites discuss kernel development at all levels of detail. Your
author would like to humbly suggest https://lwn.net/ as a source;
......
......@@ -277,36 +277,61 @@ Thunderbird (GUI)
Thunderbird is an Outlook clone that likes to mangle text, but there are ways
to coerce it into behaving.
After doing the modifications, this includes installing the extensions,
you need to restart Thunderbird.
- Allow use of an external editor:
The easiest thing to do with Thunderbird and patches is to use an
"external editor" extension and then just use your favorite ``$EDITOR``
for reading/merging patches into the body text. To do this, download
and install the extension, then add a button for it using
:menuselection:`View-->Toolbars-->Customize...` and finally just click on it
when in the :menuselection:`Compose` dialog.
Please note that "external editor" requires that your editor must not
The easiest thing to do with Thunderbird and patches is to use extensions
which open your favorite external editor.
Here are some example extensions which are capable of doing this.
- "External Editor Revived"
https://github.com/Frederick888/external-editor-revived
https://addons.thunderbird.net/en-GB/thunderbird/addon/external-editor-revived/
It requires installing a "native messaging host".
Please read the wiki which can be found here:
https://github.com/Frederick888/external-editor-revived/wiki
- "External Editor"
https://github.com/exteditor/exteditor
To do this, download and install the extension, then open the
:menuselection:`compose` window, add a button for it using
:menuselection:`View-->Toolbars-->Customize...`
then just click on the new button when you wish to use the external editor.
Please note that "External Editor" requires that your editor must not
fork, or in other words, the editor must not return before closing.
You may have to pass additional flags or change the settings of your
editor. Most notably if you are using gvim then you must pass the -f
option to gvim by putting ``/usr/bin/gvim -f`` (if the binary is in
option to gvim by putting ``/usr/bin/gvim --nofork"`` (if the binary is in
``/usr/bin``) to the text editor field in :menuselection:`external editor`
settings. If you are using some other editor then please read its manual
to find out how to do this.
To beat some sense out of the internal editor, do this:
- Edit your Thunderbird config settings so that it won't use ``format=flowed``.
Go to :menuselection:`edit-->preferences-->advanced-->config editor` to bring up
the thunderbird's registry editor.
- Edit your Thunderbird config settings so that it won't use ``format=flowed``!
Go to your main window and find the button for your main dropdown menu.
:menuselection:`Main Menu-->Preferences-->General-->Config Editor...`
to bring up the thunderbird's registry editor.
- Set ``mailnews.send_plaintext_flowed`` to ``false``
- Set ``mailnews.send_plaintext_flowed`` to ``false``
- Set ``mailnews.wraplength`` from ``72`` to ``0``
- Set ``mailnews.wraplength`` from ``72`` to ``0``
- :menuselection:`View-->Message Body As-->Plain Text`
- Don't write HTML messages! Go to the main window
:menuselection:`Main Menu-->Account Settings-->youracc@server.something-->Composition & Addressing`!
There you can disable the option "Compose messages in HTML format".
- :menuselection:`View-->Character Encoding-->Unicode (UTF-8)`
- Open messages only as plain text! Go to the main window
:menuselection:`Main Menu-->View-->Message Body As-->Plain Text`!
TkRat (GUI)
***********
......
......@@ -105,8 +105,8 @@ required reading:
patches if these rules are followed, and many people will only
review code if it is in the proper style.
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>` and :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
These files describe in explicit detail how to successfully create
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
This file describes in explicit detail how to successfully create
and send a patch, including (but not limited to):
- Email contents
......
......@@ -40,7 +40,6 @@ Other guides to the community that are of interest to most developers are:
:maxdepth: 1
changes
submitting-drivers
stable-api-nonsense
management-style
stable-kernel-rules
......
.. _kernel_docs:
Index of Documentation for People Interested in Writing and/or Understanding the Linux Kernel
=============================================================================================
Index of Further Kernel Documentation
=====================================
Juan-Mariano de Goyeneche <jmseyas@dit.upm.es>
Initial Author: Juan-Mariano de Goyeneche (<jmseyas@dit.upm.es>;
email address is defunct now.)
The need for a document like this one became apparent in the
linux-kernel mailing list as the same questions, asking for pointers
......@@ -16,21 +17,16 @@ philosophy and design decisions behind this code.
Unfortunately, not many documents are available for beginners to
start. And, even if they exist, there was no "well-known" place which
kept track of them. These lines try to cover this lack. All documents
available on line known by the author are listed, while some reference
books are also mentioned.
kept track of them. These lines try to cover this lack.
PLEASE, if you know any paper not listed here or write a new document,
send me an e-mail, and I'll include a reference to it here. Any
corrections, ideas or comments are also welcomed.
include a reference to it here, following the kernel's patch submission
process. Any corrections, ideas or comments are also welcome.
The papers that follow are listed in no particular order. All are
cataloged with the following fields: the document's "Title", the
"Author"/s, the "URL" where they can be found, some "Keywords" helpful
when searching for specific topics, and a brief "Description" of the
Document.
Enjoy!
All documents are cataloged with the following fields: the document's
"Title", the "Author"/s, the "URL" where they can be found, some
"Keywords" helpful when searching for specific topics, and a brief
"Description" of the Document.
.. note::
......@@ -83,6 +79,18 @@ On-line docs
Finally this trace-log is used as base for more a exact conceptual
exploration and description of the Linux TCP/IP implementation.*
* Title: **The Linux Kernel Module Programming Guide**
:Author: Peter Jay Salzman, Michael Burian, Ori Pomerantz, Bob Mottram,
Jim Huang.
:URL: https://sysprog21.github.io/lkmpg/
:Date: 2021
:Keywords: modules, GPL book, /proc, ioctls, system calls,
interrupt handlers .
:Description: A very nice GPL book on the topic of modules
programming. Lots of examples. Currently the new version is being
actively maintained at https://github.com/sysprog21/lkmpg.
* Title: **On submitting kernel Patches**
:Author: Andi Kleen
......@@ -126,17 +134,19 @@ On-line docs
describes how to write user-mode utilities for communicating with
Card Services.
* Title: **The Linux Kernel Module Programming Guide**
:Author: Peter Jay Salzman, Michael Burian, Ori Pomerantz, Bob Mottram,
Jim Huang.
:URL: https://sysprog21.github.io/lkmpg/
:Date: 2021
:Keywords: modules, GPL book, /proc, ioctls, system calls,
interrupt handlers .
:Description: A very nice GPL book on the topic of modules
programming. Lots of examples. Currently the new version is being
actively maintained at https://github.com/sysprog21/lkmpg.
* Title: **How NOT to write kernel drivers**
:Author: Arjan van de Ven.
:URL: https://landley.net/kdocs/ols/2002/ols2002-pages-545-555.pdf
:Date: 2002
:Keywords: driver.
:Description: Programming bugs and Do-nots in kernel driver development
:Abstract: *Quit a few tutorials, articles and books give an introduction
on how to write Linux kernel drivers. Unfortunately the things one
should NOT do in Linux kernel code is either only a minor appendix
or, more commonly, completely absent. This paper tries to briefly touch
the areas in which the most common and serious bugs and do-nots are
encountered.*
* Title: **Global spinlock list and usage**
......
.. _submittingdrivers:
Submitting Drivers For The Linux Kernel
=======================================
This document is intended to explain how to submit device drivers to the
various kernel trees. Note that if you are interested in video card drivers
you should probably talk to XFree86 (https://www.xfree86.org/) and/or X.Org
(https://x.org/) instead.
.. note::
This document is old and has seen little maintenance in recent years; it
should probably be updated or, perhaps better, just deleted. Most of
what is here can be found in the other development documents anyway.
Oh, and we don't really recommend submitting changes to XFree86 :)
Also read the :ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
document.
Allocating Device Numbers
-------------------------
Major and minor numbers for block and character devices are allocated
by the Linux assigned name and number authority (currently this is
Torben Mathiasen). The site is https://www.lanana.org/. This
also deals with allocating numbers for devices that are not going to
be submitted to the mainstream kernel.
See :ref:`Documentation/admin-guide/devices.rst <admin_devices>`
for more information on this.
If you don't use assigned numbers then when your device is submitted it will
be given an assigned number even if that is different from values you may
have shipped to customers before.
Who To Submit Drivers To
------------------------
Linux 2.0:
No new drivers are accepted for this kernel tree.
Linux 2.2:
No new drivers are accepted for this kernel tree.
Linux 2.4:
If the code area has a general maintainer then please submit it to
the maintainer listed in MAINTAINERS in the kernel file. If the
maintainer does not respond or you cannot find the appropriate
maintainer then please contact Willy Tarreau <w@1wt.eu>.
Linux 2.6 and upper:
The same rules apply as 2.4 except that you should follow linux-kernel
to track changes in API's. The final contact point for Linux 2.6+
submissions is Andrew Morton.
What Criteria Determine Acceptance
----------------------------------
Licensing:
The code must be released to us under the
GNU General Public License. If you wish the driver to be
useful to other communities such as BSD you may release
under multiple licenses. If you choose to release under
licenses other than the GPL, you should include your
rationale for your license choices in your cover letter.
See accepted licenses at include/linux/module.h
Copyright:
The copyright owner must agree to use of GPL.
It's best if the submitter and copyright owner
are the same person/entity. If not, the name of
the person/entity authorizing use of GPL should be
listed in case it's necessary to verify the will of
the copyright owner.
Interfaces:
If your driver uses existing interfaces and behaves like
other drivers in the same class it will be much more likely
to be accepted than if it invents gratuitous new ones.
If you need to implement a common API over Linux and NT
drivers do it in userspace.
Code:
Please use the Linux style of code formatting as documented
in :ref:`Documentation/process/coding-style.rst <codingStyle>`.
If you have sections of code
that need to be in other formats, for example because they
are shared with a windows driver kit and you want to
maintain them just once separate them out nicely and note
this fact.
Portability:
Pointers are not always 32bits, not all computers are little
endian, people do not all have floating point and you
shouldn't use inline x86 assembler in your driver without
careful thought. Pure x86 drivers generally are not popular.
If you only have x86 hardware it is hard to test portability
but it is easy to make sure the code can easily be made
portable.
Clarity:
It helps if anyone can see how to fix the driver. It helps
you because you get patches not bug reports. If you submit a
driver that intentionally obfuscates how the hardware works
it will go in the bitbucket.
PM support:
Since Linux is used on many portable and desktop systems, your
driver is likely to be used on such a system and therefore it
should support basic power management by implementing, if
necessary, the .suspend and .resume methods used during the
system-wide suspend and resume transitions. You should verify
that your driver correctly handles the suspend and resume, but
if you are unable to ensure that, please at least define the
.suspend method returning the -ENOSYS ("Function not
implemented") error. You should also try to make sure that your
driver uses as little power as possible when it's not doing
anything. For the driver testing instructions see
Documentation/power/drivers-testing.rst and for a relatively
complete overview of the power management issues related to
drivers see :ref:`Documentation/driver-api/pm/devices.rst <driverapi_pm_devices>`.
Control:
In general if there is active maintenance of a driver by
the author then patches will be redirected to them unless
they are totally obvious and without need of checking.
If you want to be the contact and update point for the
driver it is a good idea to state this in the comments,
and include an entry in MAINTAINERS for your driver.
What Criteria Do Not Determine Acceptance
-----------------------------------------
Vendor:
Being the hardware vendor and maintaining the driver is
often a good thing. If there is a stable working driver from
other people already in the tree don't expect 'we are the
vendor' to get your driver chosen. Ideally work with the
existing driver author to build a single perfect driver.
Author:
It doesn't matter if a large Linux company wrote the driver,
or you did. Nobody has any special access to the kernel
tree. Anyone who tells you otherwise isn't telling the
whole story.
Resources
---------
Linux kernel master tree:
ftp.\ *country_code*\ .kernel.org:/pub/linux/kernel/...
where *country_code* == your country code, such as
**us**, **uk**, **fr**, etc.
https://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git
Linux kernel mailing list:
linux-kernel@vger.kernel.org
[mail majordomo@vger.kernel.org to subscribe]
Linux Device Drivers, Third Edition (covers 2.6.10):
https://lwn.net/Kernel/LDD3/ (free version)
LWN.net:
Weekly summary of kernel development activity - https://lwn.net/
2.6 API changes:
https://lwn.net/Articles/2.6-kernel-api/
Porting drivers from prior kernels to 2.6:
https://lwn.net/Articles/driver-porting/
KernelNewbies:
Documentation and assistance for new kernel programmers
https://kernelnewbies.org/
Linux USB project:
http://www.linux-usb.org/
How to NOT write kernel driver by Arjan van de Ven:
https://landley.net/kdocs/ols/2002/ols2002-pages-545-555.pdf
Kernel Janitor:
https://kernelnewbies.org/KernelJanitors
GIT, Fast Version Control System:
https://git-scm.com/
......@@ -12,9 +12,8 @@ This document contains a large number of suggestions in a relatively terse
format. For detailed information on how the kernel development process
works, see Documentation/process/development-process.rst. Also, read
Documentation/process/submit-checklist.rst
for a list of items to check before submitting code. If you are submitting
a driver, also read Documentation/process/submitting-drivers.rst; for device
tree binding patches, read
for a list of items to check before submitting code.
For device tree binding patches, read
Documentation/devicetree/bindings/submitting-patches.rst.
This documentation assumes that you're using ``git`` to prepare your patches.
......
......@@ -1046,7 +1046,7 @@ The keyctl syscall functions are:
"filter" is either NULL to remove a watch or a filter specification to
indicate what events are required from the key.
See Documentation/watch_queue.rst for more information.
See Documentation/core-api/watch_queue.rst for more information.
Note that only one watch may be emplaced for any particular { key,
queue_fd } combination.
......
......@@ -98,6 +98,6 @@ References
See [sev-api-spec]_ for more info regarding SEV ``LAUNCH_SECRET`` operation.
.. [sev] Documentation/virt/kvm/amd-memory-encryption.rst
.. [sev] Documentation/virt/kvm/x86/amd-memory-encryption.rst
.. [secrets-coco-abi] Documentation/ABI/testing/securityfs-secrets-coco
.. [sev-api-spec] https://www.amd.com/system/files/TechDocs/55766_SEV-KM_API_Specification.pdf
......@@ -85,7 +85,7 @@ Often times the XuY functions will not be large enough, and instead you'll
want to pass a pre-filled struct to siphash. When doing this, it's important
to always ensure the struct has no padding holes. The easiest way to do this
is to simply arrange the members of the struct in descending order of size,
and to use offsetendof() instead of sizeof() for getting the size. For
and to use offsetofend() instead of sizeof() for getting the size. For
performance reasons, if possible, it's probably a good thing to align the
struct to the right boundary. Here's an example::
......
......@@ -120,14 +120,21 @@ def markup_refs(docname, app, node):
repl.append(nodes.Text(t[done:]))
return repl
#
# Keep track of cross-reference lookups that failed so we don't have to
# do them again.
#
failed_lookups = { }
def failure_seen(target):
return (target) in failed_lookups
def note_failure(target):
failed_lookups[target] = True
#
# In sphinx3 we can cross-reference to C macro and function, each one with its
# own C role, but both match the same regex, so we try both.
#
def markup_func_ref_sphinx3(docname, app, match):
class_str = ['c-func', 'c-macro']
reftype_str = ['function', 'macro']
cdom = app.env.domains['c']
#
# Go through the dance of getting an xref out of the C domain
......@@ -143,13 +150,13 @@ def markup_func_ref_sphinx3(docname, app, match):
if base_target not in Skipnames:
for target in possible_targets:
if target not in Skipfuncs:
for class_s, reftype_s in zip(class_str, reftype_str):
lit_text = nodes.literal(classes=['xref', 'c', class_s])
if (target not in Skipfuncs) and not failure_seen(target):
lit_text = nodes.literal(classes=['xref', 'c', 'c-func'])
lit_text += target_text
pxref = addnodes.pending_xref('', refdomain = 'c',
reftype = reftype_s,
reftarget = target, modname = None,
reftype = 'function',
reftarget = target,
modname = None,
classname = None)
#
# XXX The Latex builder will throw NoUri exceptions here,
......@@ -157,13 +164,14 @@ def markup_func_ref_sphinx3(docname, app, match):
#
try:
xref = cdom.resolve_xref(app.env, docname, app.builder,
reftype_s, target, pxref,
'function', target, pxref,
lit_text)
except NoUri:
xref = None
if xref:
return xref
note_failure(target)
return target_text
......
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../../disclaimer-ita.rst
:Original: Documentation/devicetree/bindings/submitting-patches.rst
================================================
Sottomettere patch per devicetree (DT) *binding*
================================================
.. note:: to be translated
......@@ -5,6 +5,7 @@
.. _it_kernel_doc:
=================================
Scrivere i commenti in kernel-doc
=================================
......@@ -469,6 +470,7 @@ Il titolo che segue ``DOC:`` funziona da intestazione all'interno del file
sorgente, ma anche come identificatore per l'estrazione di questi commenti di
documentazione. Quindi, il titolo dev'essere unico all'interno del file.
=======================================
Includere i commenti di tipo kernel-doc
=======================================
......
......@@ -5,8 +5,9 @@
.. _it_sphinxdoc:
Introduzione
============
=============================================
Usare Sphinx per la documentazione del kernel
=============================================
Il kernel Linux usa `Sphinx`_ per la generazione della documentazione a partire
dai file `reStructuredText`_ che si trovano nella cartella ``Documentation``.
......@@ -158,6 +159,9 @@ Per poter passare ulteriori opzioni a Sphinx potete utilizzare la variabile
make ``SPHINXOPTS``. Per esempio, se volete che Sphinx sia più verboso durante
la generazione potete usare il seguente comando ``make SPHINXOPTS=-v htmldocs``.
Potete anche personalizzare l'ouptut html passando un livello aggiuntivo
DOCS_CSS usando la rispettiva variabile d'ambiente ``DOCS_CSS``.
Potete eliminare la documentazione generata tramite il comando
``make cleandocs``.
......@@ -276,11 +280,11 @@ incrociato quando questa ha una voce nell'indice. Se trovate degli usi di
Tabelle a liste
---------------
Raccomandiamo l'uso delle tabelle in formato lista (*list table*). Le tabelle
in formato lista sono liste di liste. In confronto all'ASCII-art potrebbero
non apparire di facile lettura nei file in formato testo. Il loro vantaggio è
che sono facili da creare o modificare e che la differenza di una modifica è
molto più significativa perché limitata alle modifiche del contenuto.
Il formato ``list-table`` può essere utile per tutte quelle tabelle che non
possono essere facilmente scritte usando il formato ASCII-art di Sphinx. Però,
questo genere di tabelle sono illeggibili per chi legge direttamente i file di
testo. Dunque, questo formato dovrebbe essere evitato senza forti argomenti che
ne giustifichino l'uso.
La ``flat-table`` è anch'essa una lista di liste simile alle ``list-table``
ma con delle funzionalità aggiuntive:
......
......@@ -129,8 +129,7 @@ eseguiti simultaneamente.
.. warning::
Il nome 'tasklet' è ingannevole: non hanno niente a che fare
con i 'processi' ('tasks'), e probabilmente hanno più a che vedere
con qualche pessima vodka che Alexey Kuznetsov si fece a quel tempo.
con i 'processi' ('tasks').
Potete determinate se siete in un softirq (o tasklet) utilizzando la
macro :c:func:`in_softirq()` (``include/linux/preempt.h``).
......@@ -308,7 +307,7 @@ esse copiano una quantità arbitraria di dati da e verso lo spazio utente.
Al contrario di:c:func:`put_user()` e :c:func:`get_user()`, queste
funzioni ritornano la quantità di dati copiati (0 è comunque un successo).
[Sì, questa stupida interfaccia mi imbarazza. La battaglia torna in auge anno
[Sì, questa interfaccia mi imbarazza. La battaglia torna in auge anno
dopo anno. --RR]
Le funzioni potrebbero dormire implicitamente. Queste non dovrebbero mai essere
......@@ -679,9 +678,8 @@ tutti sulle spine: questo riflette cambiamenti fondamentati (eg. la funzione
non può più essere chiamata con le funzioni attive, o fa controlli aggiuntivi,
o non fa più controlli che venivano fatti in precedenza). Solitamente a questo
s'accompagna un'adeguata e completa nota sulla lista di discussone
linux-kernel; cercate negli archivi.
Solitamente eseguire una semplice sostituzione su tutto un file rendere
le cose **peggiori**.
più adatta; cercate negli archivi. Solitamente eseguire una semplice
sostituzione su tutto un file rendere le cose **peggiori**.
Inizializzazione dei campi d'una struttura
------------------------------------------
......@@ -759,14 +757,14 @@ Mettere le vostre cose nel kernel
Al fine d'avere le vostre cose in ordine per l'inclusione ufficiale, o
anche per avere patch pulite, c'è del lavoro amministrativo da fare:
- Trovare di chi è lo stagno in cui state pisciando. Guardare in cima
- Trovare chi è responsabile del codice che state modificando. Guardare in cima
ai file sorgenti, all'interno del file ``MAINTAINERS``, ed alla fine
di tutti nel file ``CREDITS``. Dovreste coordinarvi con queste persone
per evitare di duplicare gli sforzi, o provare qualcosa che è già stato
rigettato.
Assicuratevi di mettere il vostro nome ed indirizzo email in cima a
tutti i file che create o che mangeggiate significativamente. Questo è
tutti i file che create o che maneggiate significativamente. Questo è
il primo posto dove le persone guarderanno quando troveranno un baco,
o quando **loro** vorranno fare una modifica.
......@@ -787,16 +785,15 @@ anche per avere patch pulite, c'è del lavoro amministrativo da fare:
"obj-$(CONFIG_xxx) += xxx.o". La sintassi è documentata nel file
``Documentation/kbuild/makefiles.rst``.
- Aggiungete voi stessi in ``CREDITS`` se avete fatto qualcosa di notevole,
solitamente qualcosa che supera il singolo file (comunque il vostro nome
dovrebbe essere all'inizio dei file sorgenti). ``MAINTAINERS`` significa
- Aggiungete voi stessi in ``CREDITS`` se credete di aver fatto qualcosa di
notevole, solitamente qualcosa che supera il singolo file (comunque il vostro
nome dovrebbe essere all'inizio dei file sorgenti). ``MAINTAINERS`` significa
che volete essere consultati quando vengono fatte delle modifiche ad un
sottosistema, e quando ci sono dei bachi; questo implica molto di più
di un semplice impegno su una parte del codice.
sottosistema, e quando ci sono dei bachi; questo implica molto di più di un
semplice impegno su una parte del codice.
- Infine, non dimenticatevi di leggere
``Documentation/process/submitting-patches.rst`` e possibilmente anche
``Documentation/process/submitting-drivers.rst``.
``Documentation/process/submitting-patches.rst``.
Trucchetti del kernel
=====================
......
......@@ -102,16 +102,11 @@ che non esistano.
Sincronizzazione nel kernel Linux
=================================
Se posso darvi un suggerimento: non dormite mai con qualcuno più pazzo di
voi. Ma se dovessi darvi un suggerimento sulla sincronizzazione:
**mantenetela semplice**.
Se dovessi darvi un suggerimento sulla sincronizzazione: **mantenetela
semplice**.
Siate riluttanti nell'introduzione di nuovi *lock*.
Abbastanza strano, quest'ultimo è l'esatto opposto del mio suggerimento
su quando **avete** dormito con qualcuno più pazzo di voi. E dovreste
pensare a prendervi un cane bello grande.
I due principali tipi di *lock* nel kernel: spinlock e mutex
------------------------------------------------------------
......@@ -316,7 +311,7 @@ Pete Zaitcev ci offre il seguente riassunto:
- Se siete in un contesto utente (una qualsiasi chiamata di sistema)
e volete sincronizzarvi con altri processi, usate i mutex. Potete trattenere
il mutex e dormire (``copy_from_user*(`` o ``kmalloc(x,GFP_KERNEL)``).
il mutex e dormire (``copy_from_user(`` o ``kmalloc(x,GFP_KERNEL)``).
- Altrimenti (== i dati possono essere manipolati da un'interruzione) usate
spin_lock_irqsave() e spin_unlock_irqrestore().
......@@ -979,9 +974,6 @@ fallisce nel trovare quello che vuole, quindi rilascia il *lock* di lettura,
trattiene un *lock* di scrittura ed inserisce un oggetto; questo genere di
codice presenta una corsa critica.
Se non riuscite a capire il perché, per favore state alla larga dal mio
codice.
corsa fra temporizzatori: un passatempo del kernel
--------------------------------------------------
......
.. include:: ../disclaimer-ita.rst
:Original: Documentation/process/botching-up-ioctls.rst
.. _it_configuregit:
Configurare Git
===============
.. note:: To be translated
.. include:: ../disclaimer-ita.rst
:Original: :ref:`Documentation/networking/netdev-FAQ.rst <netdev-FAQ>`
:Original: :ref:`Documentation/process/maintainer-netdev.rst <netdev-FAQ>`
.. _it_netdev-FAQ:
......
......@@ -168,14 +168,15 @@ in questa ricerca:
.../scripts/get_maintainer.pl
Se questo script viene eseguito con l'opzione "-f" ritornerà il
manutentore(i) attuale per un dato file o cartella. Se viene passata una
patch sulla linea di comando, lo script elencherà i manutentori che
dovrebbero riceverne una copia. Ci sono svariate opzioni che regolano
quanto a fondo get_maintainer.pl debba cercare i manutentori;
siate quindi prudenti nell'utilizzare le opzioni più aggressive poiché
potreste finire per includere sviluppatori che non hanno un vero interesse
per il codice che state modificando.
Se questo script viene eseguito con l'opzione "-f" ritornerà il manutentore(i)
attuale per un dato file o cartella. Se viene passata una patch sulla linea di
comando, lo script elencherà i manutentori che dovrebbero riceverne una copia.
Questo è la maniera raccomandata (non quella con "-f") per ottenere la lista di
persone da aggiungere a Cc per le vostre patch. Ci sono svariate opzioni che
regolano quanto a fondo get_maintainer.pl debba cercare i manutentori; siate
quindi prudenti nell'utilizzare le opzioni più aggressive poiché potreste finire
per includere sviluppatori che non hanno un vero interesse per il codice che
state modificando.
Se tutto ciò dovesse fallire, parlare con Andrew Morton potrebbe essere
un modo efficace per capire chi è il manutentore di un dato pezzo di codice.
......
......@@ -16,9 +16,8 @@ e di procedure per la pubblicazione delle patch; seguirle renderà la vita
più facile a tutti quanti. Questo documento cercherà di coprire questi
argomenti con un ragionevole livello di dettaglio; più informazioni possono
essere trovare nella cartella 'Documentation', nei file
:ref:`translations/it_IT/process/submitting-patches.rst <it_submittingpatches>`,
:ref:`translations/it_IT/process/submitting-drivers.rst <it_submittingdrivers>`, e
:ref:`translations/it_IT/process/submit-checklist.rst <it_submitchecklist>`.
:ref:`translations/it_IT/process/submitting-patches.rst <it_submittingpatches>`
e :ref:`translations/it_IT/process/submit-checklist.rst <it_submitchecklist>`.
Quando pubblicarle
......@@ -214,13 +213,28 @@ irrilevanti (quelli generati dal processo di generazione, per esempio, o i file
di backup del vostro editor). Il file "dontdiff" nella cartella Documentation
potrà esservi d'aiuto su questo punto; passatelo a diff con l'opzione "-X".
Le etichette sopra menzionante sono usate per descrivere come i vari
sviluppatori sono stati associati allo sviluppo di una patch. Sono descritte
in dettaglio nel documento :ref:`translations/it_IT/process/submitting-patches.rst <it_submittingpatches>`;
quello che segue è un breve riassunto. Ognuna di queste righe ha il seguente
formato:
Le etichette sopracitate danno un'idea di come una patch prende vita e sono
descritte nel dettaglio nel documento
:ref:`Documentation/translations/it_IT/process/submitting-patches.rst <it_submittingpatches>`.
Qui di seguito un breve riassunto.
::
Un'etichetta ci può dire quale commit ha introdotto il problema che viene corretto nella patch::
Fixes: 1f2e3d4c5b6a ("The first line of the commit specified by the first 12 characters of its SHA-1 ID")
Un'altra etichetta viene usata per fornire collegamenti a pagine web contenenti
maggiori informazioni, per esempio un rapporto circa il baco risolto dalla
patch, oppure un documento con le specifiche implementate dalla patch::
Link: https://example.com/somewhere.html optional-other-stuff
Alcuni manutentori aggiungono quest'etichetta alla patch per fare riferimento
alla più recente discussione pubblica. A volte questo è fatto automaticamente da
alcuni strumenti come b4 or un *hook* git come quello descritto qui
'Documentation/translations/it_IT/maintainer/configure-git.rst'
Un terzo tipo di etichetta viene usato per indicare chi ha contribuito allo
sviluppo della patch. Tutte queste etichette seguono il formato::
tag: Full Name <email address> optional-other-stuff
......
......@@ -13,9 +13,8 @@ e argomenti correlati. Primo tra questi sarà sempre la cartella Documentation
che si trova nei sorgenti kernel.
Il file :ref:`process/howto.rst <it_process_howto>` è un punto di partenza
importante; :ref:`process/submitting-patches.rst <it_submittingpatches>` e
:ref:`process/submitting-drivers.rst <it_submittingdrivers>` sono
anch'essi qualcosa che tutti gli sviluppatori del kernel dovrebbero leggere.
importante; :ref:`process/submitting-patches.rst <it_submittingpatches>` è
anch'esso qualcosa che tutti gli sviluppatori del kernel dovrebbero leggere.
Molte API interne al kernel sono documentate utilizzando il meccanismo
kerneldoc; "make htmldocs" o "make pdfdocs" possono essere usati per generare
quei documenti in HTML o PDF (sebbene le versioni di TeX di alcune
......
......@@ -11,8 +11,8 @@ Requisiti minimi per compilare il kernel
Introduzione
============
Questo documento fornisce una lista dei software necessari per eseguire i
kernel 4.x.
Questo documento fornisce una lista dei software necessari per eseguire questa
versione del kernel.
Questo documento è basato sul file "Changes" del kernel 2.0.x e quindi le
persone che lo scrissero meritano credito (Jared Mauch, Axel Boldt,
......@@ -32,12 +32,13 @@ PC Card, per esempio, probabilmente non dovreste preoccuparvi di pcmciautils.
====================== ================= ========================================
Programma Versione minima Comando per verificare la versione
====================== ================= ========================================
GNU C 4.9 gcc --version
Clang/LLVM (optional) 10.0.1 clang --version
GNU C 5.1 gcc --version
Clang/LLVM (optional) 11.0.0 clang --version
GNU make 3.81 make --version
binutils 2.23 ld -v
flex 2.5.35 flex --version
bison 2.0 bison --version
pahole 1.16 pahole --version
util-linux 2.10o fdformat --version
kmod 13 depmod -V
e2fsprogs 1.41.4 e2fsck -V
......@@ -58,6 +59,7 @@ iptables 1.4.2 iptables -V
openssl & libcrypto 1.0.0 openssl version
bc 1.06.95 bc --version
Sphinx\ [#f1]_ 1.7 sphinx-build --version
cpio any cpio --version
====================== ================= ========================================
.. [#f1] Sphinx è necessario solo per produrre la documentazione del Kernel
......@@ -111,6 +113,16 @@ Bison
Dalla versione 4.16, il sistema di compilazione, durante l'esecuzione, genera
un parsificatore. Questo richiede bison 2.0 o successivo.
pahole
------
Dalla versione 5.2, quando viene impostato CONFIG_DEBUG_INFO_BTF, il sistema di
compilazione genera BTF (BPF Type Format) a partire da DWARF per vmlinux. Più
tardi anche per i moduli. Questo richiede pahole v1.16 o successivo.
A seconda della distribuzione, lo si può trovare nei pacchetti 'dwarves' o
'pahole'. Oppure lo si può trovare qui: https://fedorapeople.org/~acme/dwarves/.
Perl
----
......@@ -455,6 +467,11 @@ mcelog
- <http://www.mcelog.org/>
cpio
----
- <https://www.gnu.org/software/cpio/>
Rete
****
......
......@@ -466,14 +466,52 @@ la riga della parentesi graffa di chiusura. Ad esempio:
}
EXPORT_SYMBOL(system_is_up);
6.1) Prototipi di funzione
**************************
Nei prototipi di funzione, includete i nomi dei parametri e i loro tipi.
Nonostante questo non sia richiesto dal linguaggio C, in Linux viene preferito
perché è un modo semplice per aggiungere informazioni importanti per il
lettore.
Non usate la parola chiave ``extern`` coi prototipi di funzione perché
Non usate la parola chiave ``extern`` con le dichiarazioni di funzione perché
rende le righe più lunghe e non è strettamente necessario.
Quando scrivete i prototipi di funzione mantenete `l'ordine degli elementi <https://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@mail.gmail.com/>`_.
Prendiamo questa dichiarazione di funzione come esempio::
__init void * __must_check action(enum magic value, size_t size, u8 count,
char *fmt, ...) __printf(4, 5) __malloc;
L'ordine suggerito per gli elementi di un prototipo di funzione è il seguente:
- classe d'archiviazione (in questo caso ``static __always_inline``. Da notare
che ``__always_inline`` è tecnicamente un attributo ma che viene trattato come
``inline``)
- attributi della classe di archiviazione (in questo caso ``__init``, in altre
parole la sezione, ma anche cose tipo ``__cold``)
- il tipo di ritorno (in questo caso, ``void *``)
- attributi per il valore di ritorno (in questo caso, ``__must_check``)
- il nome della funzione (in questo caso, ``action``)
- i parametri della funzione(in questo caso,
``(enum magic value, size_t size, u8 count, char *fmt, ...)``,
da notare che va messo anche il nome del parametro)
- attributi dei parametri (in questo caso, ``__printf(4, 5)``)
- attributi per il comportamento della funzione (in questo caso, ``__malloc_``)
Notate che per la **definizione** di una funzione (il altre parole il corpo
della funzione), il compilatore non permette di usare gli attributi per i
parametri dopo i parametri. In questi casi, devono essere messi dopo gli
attributi della classe d'archiviazione (notate che la posizione di
``__printf(4,5)`` cambia rispetto alla **dichiarazione**)::
static __always_inline __init __printf(4, 5) void * __must_check action(enum magic value,
size_t size, u8 count, char *fmt, ...) __malloc
{
...
}*)**``)**``)``)``*)``)``)``)``*``)``)``)*)
7) Centralizzare il ritorno delle funzioni
------------------------------------------
......@@ -855,7 +893,7 @@ I messaggi del kernel non devono terminare con un punto fermo.
Scrivere i numeri fra parentesi (%d) non migliora alcunché e per questo
dovrebbero essere evitati.
Ci sono alcune macro per la diagnostica in <linux/device.h> che dovreste
Ci sono alcune macro per la diagnostica in <linux/dev_printk.h> che dovreste
usare per assicurarvi che i messaggi vengano associati correttamente ai
dispositivi e ai driver, e che siano etichettati correttamente: dev_err(),
dev_warn(), dev_info(), e così via. Per messaggi che non sono associati ad
......
......@@ -69,8 +69,8 @@ dovrebbero essere fatto negli argomenti di funzioni di allocazione di memoria
piccoli di quelli che il chiamante si aspettava. L'uso di questo modo di
allocare può portare ad un overflow della memoria di heap e altri
malfunzionamenti. (Si fa eccezione per valori numerici per i quali il
compilatore può generare avvisi circa un potenziale overflow. Tuttavia usare
i valori numerici come suggerito di seguito è innocuo).
compilatore può generare avvisi circa un potenziale overflow. Tuttavia, anche in
questi casi è preferibile riscrivere il codice come suggerito di seguito).
Per esempio, non usate ``count * size`` come argomento::
......@@ -80,6 +80,9 @@ Al suo posto, si dovrebbe usare l'allocatore a due argomenti::
foo = kmalloc_array(count, size, GFP_KERNEL);
Nello specifico, kmalloc() può essere sostituta da kmalloc_array(), e kzalloc()
da kcalloc().
Se questo tipo di allocatore non è disponibile, allora dovrebbero essere usate
le funzioni del tipo *saturate-on-overflow*::
......@@ -100,9 +103,20 @@ Invece, usate la seguente funzione::
invitati a riorganizzare il vostro codice usando il
`flexible array member <#zero-length-and-one-element-arrays>`_.
Per maggiori dettagli fate riferimento a array_size(),
array3_size(), e struct_size(), così come la famiglia di
funzioni check_add_overflow() e check_mul_overflow().
Per altri calcoli, usate le funzioni size_mul(), size_add(), e size_sub(). Per
esempio, al posto di::
foo = krealloc(current_size + chunk_size * (count - 3), GFP_KERNEL);
dovreste scrivere:
foo = krealloc(size_add(current_size,
size_mul(chunk_size,
size_sub(count, 3))), GFP_KERNEL);
Per maggiori dettagli fate riferimento a array3_size() e flex_array_size(), ma
anche le funzioni della famiglia check_mul_overflow(), check_add_overflow(),
check_sub_overflow(), e check_shl_overflow().
simple_strtol(), simple_strtoll(), simple_strtoul(), simple_strtoull()
----------------------------------------------------------------------
......
......@@ -109,8 +109,7 @@ Di seguito una lista di file che sono presenti nei sorgente del kernel e che
accetteranno patch solo se queste osserveranno tali regole, e molte
persone revisioneranno il codice solo se scritto nello stile appropriato.
:ref:`Documentation/translations/it_IT/process/submitting-patches.rst <it_submittingpatches>` e
:ref:`Documentation/translations/it_IT/process/submitting-drivers.rst <it_submittingdrivers>`
:ref:`Documentation/translations/it_IT/process/submitting-patches.rst <it_submittingpatches>`
Questo file descrive dettagliatamente come creare ed inviare una patch
con successo, includendo (ma non solo questo):
......
......@@ -41,12 +41,12 @@ degli sviluppatori:
:maxdepth: 1
changes
submitting-drivers
stable-api-nonsense
management-style
stable-kernel-rules
submit-checklist
kernel-docs
maintainers
Ed infine, qui ci sono alcune guide più tecniche che son state messe qua solo
perché non si è trovato un posto migliore.
......
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-ita.rst
:Original: Documentation/process/maintainer-handbooks.rst
:Translator: Federico Vaga <federico.vaga@vaga.pv.it>
.. _it_maintainer_handbooks_main:
Note sul processo di sviluppo dei sottosistemi e dei sorgenti dei manutentori
=============================================================================
Lo scopo di questo documento è quello di fornire informazioni sul processo di
sviluppo dedicate ai sottosistemi che vanno ad integrare quelle più generali
descritte in :ref:`Documentation/translations/it_IT/process
<it_development_process_main>`.
Indice:
.. toctree::
:numbered:
:maxdepth: 2
maintainer-tip
......@@ -931,12 +931,11 @@ che avete nel vostro portachiavi::
uid [ unknown] Linus Torvalds <torvalds@kernel.org>
sub rsa2048 2011-09-20 [E]
Poi, aprite il `PGP pathfinder`_. Nel campo "From", incollate l'impronta
digitale della chiave di Linus Torvalds che si vede nell'output qui sopra.
Nel campo "to", incollate il key-id della chiave sconosciuta che avete
trovato con ``gpg --search``, e poi verificare il risultato:
- `Finding paths to Linus`_
Poi, cercate un percorso affidabile da Linux Torvalds alla chiave che avete
trovato con ``gpg --search`` usando la chiave sconosciuta.Per farlo potete usare
diversi strumenti come https://github.com/mricon/wotmate,
https://git.kernel.org/pub/scm/docs/kernel/pgpkeys.git/tree/graphs, e
https://the.earth.li/~noodles/pathfind.html.
Se trovate un paio di percorsi affidabili è un buon segno circa la validità
della chiave. Ora, potete aggiungerla al vostro portachiavi dal keyserver::
......@@ -948,6 +947,3 @@ fiducia nell'amministratore del servizio *PGP Pathfinder* sperando che non
sia malintenzionato (infatti, questo va contro :ref:`it_devs_not_infra`).
Tuttavia, se mantenete con cura la vostra rete di fiducia sarà un deciso
miglioramento rispetto alla cieca fiducia nei keyserver.
.. _`PGP pathfinder`: https://pgp.cs.uu.nl/
.. _`Finding paths to Linus`: https://pgp.cs.uu.nl/paths/79BE3E4300411886/to/C94035C21B4F2AEB.html
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-ita.rst
:Original: Documentation/process/maintainer-tip.rst
Il tascabile dei sorgenti tip
=============================
.. note:: To be translated
:Original: Documentation/process/maintainers.rst
Lista dei manutentori e come inviare modifiche al kernel
========================================================
Questa pagina non verrà tradotta. Fate riferimento alla versione originale in
inglese.
.. note:: La pagina originale usa una direttiva speciale per integrare il file
`MAINTAINERS` in sphinx. La parte di quel documento che si potrebbe
tradurre contiene comunque informazioni già presenti in
:ref:`Documentation/translations/it_IT/process/submitting-patches.rst
<it_submittingpatches>`.
......@@ -41,11 +41,11 @@ Regole sul tipo di patch che vengono o non vengono accettate nei sorgenti
Procedura per sottomettere patch per i sorgenti -stable
-------------------------------------------------------
- Una patch di sicurezza non dovrebbero essere gestite (solamente) dal processo
.. note::
Una patch di sicurezza non dovrebbe essere gestita (solamente) dal processo
di revisione -stable, ma dovrebbe seguire le procedure descritte in
:ref:`Documentation/translations/it_IT/admin-guide/security-bugs.rst <it_securitybugs>`.
Per tutte le altre sottomissioni, scegliere una delle seguenti procedure
------------------------------------------------------------------------
......@@ -90,9 +90,9 @@ L':ref:`it_option_2` e l':ref:`it_option_3` sono più utili quando, al momento
dell'inclusione dei sorgenti principali, si ritiene che non debbano essere
incluse anche in quelli stabili (per esempio, perché si crede che si dovrebbero
fare più verifiche per eventuali regressioni). L':ref:`it_option_3` è
particolarmente utile se la patch ha bisogno di qualche modifica per essere
applicata ad un kernel più vecchio (per esempio, perché nel frattempo l'API è
cambiata).
particolarmente utile se una patch dev'essere riportata su una versione
precedente (per esempio la patch richiede modifiche a causa di cambiamenti di
API).
Notate che per l':ref:`it_option_3`, se la patch è diversa da quella nei
sorgenti principali (per esempio perché è stato necessario un lavoro di
......@@ -167,9 +167,18 @@ Ciclo di una revisione
della lista linux-kernel obietta la bontà della patch, sollevando problemi
che i manutentori ed i membri non avevano compreso, allora la patch verrà
rimossa dalla coda.
- Alla fine del ciclo di revisione tutte le patch che hanno ricevuto l'ACK
verranno aggiunte per il prossimo rilascio -stable, e successivamente
questo nuovo rilascio verrà fatto.
- Le patch che hanno ricevuto un ACK verranno inviate nuovamente come parte di
un rilascio candidato (-rc) al fine di essere verificate dagli sviluppatori e
dai testatori.
- Solitamente si pubblica solo una -rc, tuttavia se si riscontrano problemi
importanti, alcune patch potrebbero essere modificate o essere scartate,
oppure nuove patch potrebbero essere messe in coda. Dunque, verranno pubblicate
nuove -rc e così via finché non si ritiene che non vi siano più problemi.
- Si può rispondere ad una -rc scrivendo sulla lista di discussione un'email
con l'etichetta "Tested-by:". Questa etichetta verrà raccolta ed aggiunta al
commit rilascio.
- Alla fine del ciclo di revisione il nuovo rilascio -stable conterrà tutte le
patch che erano in coda e sono state verificate.
- Le patch di sicurezza verranno accettate nei sorgenti -stable direttamente
dalla squadra per la sicurezza del kernel, e non passerà per il normale
ciclo di revisione. Contattate la suddetta squadra per maggiori dettagli
......@@ -186,8 +195,19 @@ Sorgenti
- Il rilascio definitivo, e marchiato, di tutti i kernel stabili può essere
trovato in rami distinti per versione al seguente indirizzo:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
- I rilasci candidati di tutti i kernel stabili possono essere trovati al
seguente indirizzo:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git/
.. warning::
I sorgenti -stable-rc sono un'istantanea dei sorgenti stable-queue e
subirà frequenti modifiche, dunque verrà anche trapiantato spesso.
Dovrebbe essere usato solo allo scopo di verifica (per esempio in un
sistema di CI)
Comitato per la revisione
-------------------------
......
.. include:: ../disclaimer-ita.rst
:Original: :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
:Translator: Federico Vaga <federico.vaga@vaga.pv.it>
.. _it_submittingdrivers:
Sottomettere driver per il kernel Linux
=======================================
.. note::
Questo documento è vecchio e negli ultimi anni non è stato più aggiornato;
dovrebbe essere aggiornato, o forse meglio, rimosso. La maggior parte di
quello che viene detto qui può essere trovato anche negli altri documenti
dedicati allo sviluppo. Per questo motivo il documento non verrà tradotto.
......@@ -18,16 +18,18 @@ Questo documento contiene un vasto numero di suggerimenti concisi. Per maggiori
dettagli su come funziona il processo di sviluppo del kernel leggete
Documentation/translations/it_IT/process/development-process.rst. Leggete anche
Documentation/translations/it_IT/process/submit-checklist.rst per una lista di
punti da verificare prima di inviare del codice. Se state inviando un driver,
allora leggete anche
Documentation/translations/it_IT/process/submitting-drivers.rst; per delle patch
relative alle associazioni per Device Tree leggete
punti da verificare prima di inviare del codice.
Per delle patch relative alle associazioni per Device Tree leggete
Documentation/translations/it_IT/process/submitting-patches.rst.
Questa documentazione assume che sappiate usare ``git`` per preparare le patch.
Se non siete pratici di ``git``, allora è bene che lo impariate;
renderà la vostra vita di sviluppatore del kernel molto più semplice.
I sorgenti di alcuni sottosistemi e manutentori contengono più informazioni
riguardo al loro modo di lavorare ed aspettative. Consultate
:ref:`Documentation/translations/it_IT/process/maintainer-handbooks.rst <it_maintainer_handbooks_main>`
Ottenere i sorgenti attuali
---------------------------
......@@ -84,11 +86,11 @@ comporti come descritto.
I manutentori vi saranno grati se scrivete la descrizione della patch in un
formato che sia compatibile con il gestore dei sorgenti usato dal kernel,
``git``, come un "commit log". Leggete :ref:`it_explicit_in_reply_to`.
``git``, come un "commit log". Leggete :ref:`it_the_canonical_patch_format`.
Risolvete solo un problema per patch. Se la vostra descrizione inizia ad
essere lunga, potrebbe essere un segno che la vostra patch necessita d'essere
divisa. Leggete :ref:`split_changes`.
divisa. Leggete :ref:`it_split_changes`.
Quando inviate o rinviate una patch o una serie, includete la descrizione
completa delle modifiche e la loro giustificazione. Non limitatevi a dire che
......@@ -104,17 +106,28 @@ do frotz" piuttosto che "[This patch] makes xyzzy do frotz" or "[I] changed
xyzzy to do frotz", come se steste dando ordini al codice di cambiare il suo
comportamento.
Se la patch corregge un baco conosciuto, fare riferimento a quel baco inserendo
il suo numero o il suo URL. Se la patch è la conseguenza di una discussione
su una lista di discussione, allora fornite l'URL all'archivio di quella
discussione; usate i collegamenti a https://lore.kernel.org/ con il
``Message-Id``, in questo modo vi assicurerete che il collegamento non diventi
invalido nel tempo.
Se ci sono delle discussioni, o altre informazioni d'interesse, che fanno
riferimento alla patch, allora aggiungete l'etichetta 'Link:' per farvi
riferimento. Per esempio, se la vostra patch corregge un baco potete aggiungere
quest'etichetta per fare riferimento ad un rapporto su una lista di discussione
o un *bug tracker*. Un altro esempio; potete usare quest'etichetta per far
riferimento ad una discussione precedentemente avvenuta su una lista di
discussione, o qualcosa di documentato sul web, da cui poi è nata la patch in
questione.
Quando volete fare riferimento ad una lista di discussione, preferite il
servizio d'archiviazione lore.kernel.org. Per create un collegamento URL è
sufficiente usare il campo ``Message-Id``, presente nell'intestazione del
messaggio, senza parentesi angolari. Per esempio::
Link: https://lore.kernel.org/r/30th.anniversary.repost@klaava.Helsinki.FI/
Prima d'inviare il messaggio ricordatevi di verificare che il collegamento così
creato funzioni e che indirizzi verso il messaggio desiderato.
Tuttavia, cercate di rendere la vostra spiegazione comprensibile anche senza
far riferimento a fonti esterne. In aggiunta ai collegamenti a bachi e liste
di discussione, riassumente i punti più importanti della discussione che hanno
portato alla creazione della patch.
Tuttavia, provate comunque a dare una spiegazione comprensibile anche senza
accedere alle fonti esterne. Inoltre, riassumente i punti più salienti che hanno
condotto all'invio della patch.
Se volete far riferimento a uno specifico commit, non usate solo
l'identificativo SHA-1. Per cortesia, aggiungete anche la breve riga
......@@ -227,9 +240,10 @@ nella vostra patch.
Dovreste sempre inviare una copia della patch ai manutentori dei sottosistemi
interessati dalle modifiche; date un'occhiata al file MAINTAINERS e alla storia
delle revisioni per scoprire chi si occupa del codice. Lo script
scripts/get_maintainer.pl può esservi d'aiuto. Se non riuscite a trovare un
manutentore per il sottosistema su cui state lavorando, allora Andrew Morton
(akpm@linux-foundation.org) sarà la vostra ultima possibilità.
scripts/get_maintainer.pl può esservi d'aiuto (passategli il percorso alle
vostre patch). Se non riuscite a trovare un manutentore per il sottosistema su
cui state lavorando, allora Andrew Morton (akpm@linux-foundation.org) sarà la
vostra ultima possibilità.
Normalmente, dovreste anche scegliere una lista di discussione a cui inviare la
vostra serie di patch. La lista di discussione linux-kernel@vger.kernel.org
......@@ -324,14 +338,19 @@ cosa stia accadendo.
Assicuratevi di dire ai revisori quali cambiamenti state facendo e di
ringraziarli per il loro tempo. Revisionare codice è un lavoro faticoso e che
richiede molto tempo, e a volte i revisori diventano burberi. Tuttavia, anche
in questo caso, rispondete con educazione e concentratevi sul problema che
hanno evidenziato.
richiede molto tempo, e a volte i revisori diventano burberi. Tuttavia, anche in
questo caso, rispondete con educazione e concentratevi sul problema che hanno
evidenziato. Quando inviate una version successiva ricordatevi di aggiungere un
``patch changelog`` alla email di intestazione o ad ogni singola patch spiegando
le differenze rispetto a sottomissioni precedenti (vedere
:ref:`it_the_canonical_patch_format`).
Leggete Documentation/translations/it_IT/process/email-clients.rst per
le raccomandazioni sui programmi di posta elettronica e l'etichetta da usare
sulle liste di discussione.
.. _it_resend_reminders:
Non scoraggiatevi - o impazientitevi
------------------------------------
......@@ -504,7 +523,8 @@ Utilizzare Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: e Fixes:
L'etichetta Reported-by da credito alle persone che trovano e riportano i bachi
e si spera che questo possa ispirarli ad aiutarci nuovamente in futuro.
Rammentate che se il baco è stato riportato in privato, dovrete chiedere il
permesso prima di poter utilizzare l'etichetta Reported-by.
permesso prima di poter utilizzare l'etichetta Reported-by. Questa etichetta va
usata per i bachi, dunque non usatela per richieste di nuove funzionalità.
L'etichetta Tested-by: indica che la patch è stata verificata con successo
(su un qualche sistema) dalla persona citata. Questa etichetta informa i
......@@ -574,6 +594,8 @@ previste per i kernel stabili, e nemmeno dalla necessità di aggiungere
in copia conoscenza stable@vger.kernel.org su tutte le patch per
suddetti kernel.
.. _it_the_canonical_patch_format:
Il formato canonico delle patch
-------------------------------
......@@ -719,6 +741,8 @@ messe correttamente oltre la riga.::
Maggiori dettagli sul formato delle patch nei riferimenti qui di seguito.
.. _it_backtraces:
Aggiungere i *backtrace* nei messaggi di commit
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
......
......@@ -129,8 +129,8 @@ linux-api@vger.kernel.org に送ることを勧めます。
ルに従っているものだけを受け付け、多くの人は正しいスタイルのコード
だけをレビューします。
:ref:`Documentation/process/submitting-patches.rst <codingstyle>` と :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
れらのファイルには、どうやってうまくパッチを作って投稿するかにつ
:ref:`Documentation/process/submitting-patches.rst <codingstyle>`
このファイルには、どうやってうまくパッチを作って投稿するかにつ
いて非常に詳しく書かれており、以下を含みます (これだけに限らない
けれども)
......
......@@ -124,7 +124,7 @@ mtk.manpages@gmail.com의 메인테이너에게 보낼 것을 권장한다.
메인테이너들은 이 규칙을 따르는 패치들만을 받아들일 것이고 많은 사람들이
그 패치가 올바른 스타일일 경우만 코드를 검토할 것이다.
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>` 와 :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
:ref:`Documentation/process/submitting-patches.rst <submittingpatches>`
이 파일들은 성공적으로 패치를 만들고 보내는 법을 다음의 내용들로
굉장히 상세히 설명하고 있다(그러나 다음으로 한정되진 않는다).
......
......@@ -123,14 +123,14 @@ nr_virtfn'是要启用的VF的编号。
...
}
static int dev_suspend(struct pci_dev *dev, pm_message_t state)
static int dev_suspend(struct device *dev)
{
...
return 0;
}
static int dev_resume(struct pci_dev *dev)
static int dev_resume(struct device *dev)
{
...
......@@ -163,8 +163,7 @@ nr_virtfn'是要启用的VF的编号。
.id_table = dev_id_table,
.probe = dev_probe,
.remove = dev_remove,
.suspend = dev_suspend,
.resume = dev_resume,
.driver.pm = &dev_pm_ops
.shutdown = dev_shutdown,
.sriov_configure = dev_sriov_configure,
};
......@@ -255,13 +255,13 @@ pci_set_master()将通过设置PCI_COMMAND寄存器中的总线主控位来启
虽然所有的驱动程序都应该明确指出PCI总线主控的DMA功能(如32位或64位),但对于流式
数据来说,具有超过32位总线主站功能的设备需要驱动程序通过调用带有适当参数的
``pci_set_dma_mask()`` 来“注册”这种功能。一般来说,在系统RAM高于4G物理地址的情
``dma_set_mask()`` 来“注册”这种功能。一般来说,在系统RAM高于4G物理地址的情
况下,这允许更有效的DMA。
所有PCI-X和PCIe兼容设备的驱动程序必须调用 ``pci_set_dma_mask()`` ,因为它们
所有PCI-X和PCIe兼容设备的驱动程序必须调用 ``dma_set_mask()`` ,因为它们
是64位DMA设备。
同样,如果设备可以通过调用 ``pci_set_consistent_dma_mask()`` 直接寻址到
同样,如果设备可以通过调用 ``dma_set_coherent_mask()`` 直接寻址到
4G物理地址以上的系统RAM中的“一致性内存”,那么驱动程序也必须“注册”这种功能。同
样,这包括所有PCI-X和PCIe兼容设备的驱动程序。许多64位“PCI”设备(在PCI-X之前)
和一些PCI-X设备对有效载荷(“流式”)数据具有64位DMA功能,但对控制(“一致性”)数
......
......@@ -36,6 +36,7 @@ Todolist:
:maxdepth: 1
reporting-issues
reporting-regressions
security-bugs
bug-hunting
bug-bisect
......@@ -44,7 +45,6 @@ Todolist:
Todolist:
* reporting-bugs
* ramoops
* dynamic-debug-howto
* kdump/index
......
......@@ -210,6 +210,8 @@ schemes/<N>/
- ``pageout``: 为具有 ``MADV_PAGEOUT`` 的区域调用 ``madvise()`` 。
- ``hugepage``: 为带有 ``MADV_HUGEPAGE`` 的区域调用 ``madvise()`` 。
- ``nohugepage``: 为带有 ``MADV_NOHUGEPAGE`` 的区域调用 ``madvise()``。
- ``lru_prio``: 在其LRU列表上对区域进行优先排序。
- ``lru_deprio``: 对区域的LRU列表进行降低优先处理。
- ``stat``: 什么都不做,只计算统计数据
schemes/<N>/access_pattern/
......
......@@ -5,6 +5,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
:校译:
......@@ -278,6 +279,11 @@ HyperSparc cpu就是这样一个具有这种属性的cpu。
CPU上,因为它将cpu存储到页面上,使其变脏。同样,请看
sparc64关于如何处理这个问题的例子。
``void flush_dcache_folio(struct folio *folio)``
该函数的调用情形与flush_dcache_page()相同。它允许架构针对刷新整个
folio页面进行优化,而不是一次刷新一页。
``void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
unsigned long user_vaddr, void *dst, void *src, int len)``
``void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
......
......@@ -28,6 +28,7 @@
printk-basics
printk-formats
workqueue
watch_queue
symbol-namespaces
数据结构和低级实用程序
......
......@@ -5,6 +5,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
.. _cn_irq-domain.rst:
......@@ -52,8 +53,18 @@ irq_domain和一个hwirq号作为参数。 如果hwirq的映射还不存在,
一个新的Linux irq_desc,将其与hwirq关联起来,并调用.map()回调,这样驱动
程序就可以执行任何必要的硬件设置。
当接收到一个中断时,应该使用irq_find_mapping()函数从hwirq号中找到
Linux IRQ号。
一旦建立了映射,可以通过多种方法检索或使用它:
- irq_resolve_mapping()返回一个指向给定域和hwirq号的irq_desc结构指针,
如果没有映射则返回NULL。
- irq_find_mapping()返回给定域和hwirq的Linux IRQ号,如果没有映射则返回0。
- irq_linear_revmap()现与irq_find_mapping()相同,已被废弃。
- generic_handle_domain_irq()处理一个由域和hwirq号描述的中断。
请注意,irq域的查找必须发生在与RCU读临界区兼容的上下文中。
在调用irq_find_mapping()之前,至少要调用一次irq_create_mapping()函数,
以免描述符不能被分配。
......@@ -119,7 +130,8 @@ irq_domain_add_tree()和irq_domain_create_tree()在功能上是等价的,除
Linux IRQ号编入硬件本身,这样就不需要映射了。 调用irq_create_direct_mapping()
会分配一个Linux IRQ号,并调用.map()回调,这样驱动就可以将Linux IRQ号编入硬件中。
大多数驱动程序不能使用这个映射。
大多数驱动程序无法使用此映射,现在它由CONFIG_IRQ_DOMAIN_NOMAP选项控制。
请不要引入此API的新用户。
传统映射类型
------------
......@@ -128,7 +140,6 @@ Linux IRQ号编入硬件本身,这样就不需要映射了。 调用irq_create
irq_domain_add_simple()
irq_domain_add_legacy()
irq_domain_add_legacy_isa()
irq_domain_create_simple()
irq_domain_create_legacy()
......@@ -137,6 +148,9 @@ Linux IRQ号编入硬件本身,这样就不需要映射了。 调用irq_create
一组用于IRQ号的定义(#define),这些定义被传递给struct设备注册。 在这种情况下,
不能动态分配Linux IRQ号,应该使用传统映射。
顾名思义,\*_legacy()系列函数已被废弃,只是为了方便对古老平台的支持而存在。
不应该增加新的用户。当\*_simple()系列函数的使用导致遗留行为时,他们也是如此。
传统映射假设已经为控制器分配了一个连续的IRQ号范围,并且可以通过向hwirq号添加一
个固定的偏移来计算IRQ号,反之亦然。 缺点是需要中断控制器管理IRQ分配,并且需要为每
个hwirq分配一个irq_desc,即使它没有被使用。
......
......@@ -5,6 +5,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
.. _cn_kernel-api.rst:
......@@ -282,6 +283,8 @@ kernel/acct.c
该API在以下内核代码中:
include/linux/bio.h
block/blk-core.c
block/blk-core.c
......
......@@ -5,6 +5,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
:校译:
......@@ -66,12 +67,24 @@ mm/vmalloc.c
该API在以下内核代码中:
mm/readahead.c
文件映射
--------
mm/filemap.c
预读
----
mm/readahead.c
回写
----
mm/page-writeback.c
截断
----
mm/truncate.c
include/linux/pagemap.h
......@@ -105,6 +118,14 @@ mm/mempolicy.c
include/linux/mm_types.h
include/linux/mm_inline.h
include/linux/page-flags.h
include/linux/mm.h
include/linux/page_ref.h
include/linux/mmzone.h
mm/util.c
......@@ -6,6 +6,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
.. _cn_printk-basics.rst:
......@@ -107,6 +108,4 @@ pr_debug()和pr_devel(),除非定义了 ``DEBUG`` (或者在pr_debug()的情
该API在以下内核代码中:
kernel/printk/printk.c
include/linux/printk.h
......@@ -5,6 +5,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
.. _cn_printk-formats.rst:
......@@ -548,7 +549,7 @@ nodemask_pr_args()来方便打印cpumask和nodemask。
::
%pGp referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff
%pGp 0x17ffffc0002036(referenced|uptodate|lru|active|private|node=0|zone=2|lastcpupid=0x1fffff)
%pGg GFP_USER|GFP_DMA32|GFP_NOWARN
%pGv read|exec|mayread|maywrite|mayexec|denywrite
......
This diff is collapsed.
......@@ -6,6 +6,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
.. _cn_workqueue.rst:
......@@ -178,10 +179,6 @@ workqueue将自动创建与属性相匹配的后备工作者池。调节并发
这个标志对于未绑定的wq来说是没有意义的。
请注意,标志 ``WQ_NON_REENTRANT`` 不再存在,因为现在所有的工作
队列都是不可逆的——任何工作项都保证在任何时间内最多被整个系统的一
个工作者执行。
``max_active``
--------------
......@@ -328,6 +325,22 @@ And with cmwq with ``@max_active`` >= 3, ::
工作项函数在堆栈追踪中应该是微不足道的。
不可重入条件
============
工作队列保证,如果在工作项排队后满足以下条件,则工作项不能重入:
1. 工作函数没有被改变。
2. 没有人将该工作项排到另一个工作队列中。
3. 该工作项尚未被重新启动。
换言之,如果上述条件成立,则保证在任何给定时间最多由一个系统范围内的工作程序执行
该工作项。
请注意,在self函数中将工作项重新排队(到同一队列)不会破坏这些条件,因此可以安全
地执行此操作。否则在破坏工作函数内部的条件时需要小心。
内核内联文档参考
================
......
......@@ -6,6 +6,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
周彬彬 Binbin Zhou <zhoubinbin@loongson.cn>
:校译:
......@@ -254,7 +255,8 @@ __xa_set_mark() 和 __xa_clear_mark() 函数也适用于你查找一个条目并
高级API是基于xa_state的。这是一个不透明的数据结构,你使用XA_STATE()宏在堆栈中声明。这个宏初始化了
xa_state,准备开始在XArray上移动。它被用作一个游标来保持在XArray中的位置,并让你把各种操作组合在一
起,而不必每次都从头开始。
起,而不必每次都从头开始。xa_state的内容受rcu_read_lock()或xas_lock()的保护。如果需要删除保护状态
和树的这些锁中的任何一个,你必须调用xas_pause()以便将来的调用不会依赖于状态中未受保护的部分。
xa_state也被用来存储错误(store errors)。你可以调用xas_error()来检索错误。所有的操作在进行之前都
会检查xa_state是否处于错误状态,所以你没有必要在每次调用之后检查错误;你可以连续进行多次调用,只在
......
......@@ -11,34 +11,65 @@
概述
----
KernelAddressSANitizer(KASAN)是一种动态内存安全错误检测工具,主要功能是
检查内存越界访问和使用已释放内存的问题。KASAN有三种模式:
Kernel Address SANitizer(KASAN)是一种动态内存安全错误检测工具,主要功能是
检查内存越界访问和使用已释放内存的问题。
1. 通用KASAN(与用户空间的ASan类似)
2. 基于软件标签的KASAN(与用户空间的HWASan类似)
3. 基于硬件标签的KASAN(基于硬件内存标签)
KASAN有三种模式:
由于通用KASAN的内存开销较大,通用KASAN主要用于调试。基于软件标签的KASAN
可用于dogfood测试,因为它具有较低的内存开销,并允许将其用于实际工作量。
基于硬件标签的KASAN具有较低的内存和性能开销,因此可用于生产。同时可用于
检测现场内存问题或作为安全缓解措施。
1. 通用KASAN
2. 基于软件标签的KASAN
3. 基于硬件标签的KASAN
软件KASAN模式(#1和#2)使用编译时工具在每次内存访问之前插入有效性检查,
因此需要一个支持它的编译器版本
用CONFIG_KASAN_GENERIC启用的通用KASAN,是用于调试的模式,类似于用户空
间的ASan。这种模式在许多CPU架构上都被支持,但它有明显的性能和内存开销
通用KASAN在GCC和Clang受支持。GCC需要8.3.0或更高版本。任何受支持的Clang
版本都是兼容的,但从Clang 11才开始支持检测全局变量的越界访问。
基于软件标签的KASAN或SW_TAGS KASAN,通过CONFIG_KASAN_SW_TAGS启用,
可以用于调试和自我测试,类似于用户空间HWASan。这种模式只支持arm64,但其
适度的内存开销允许在内存受限的设备上用真实的工作负载进行测试。
基于软件标签的KASAN模式仅在Clang中受支持。
基于硬件标签的KASAN或HW_TAGS KASAN,用CONFIG_KASAN_HW_TAGS启用,被
用作现场内存错误检测器或作为安全缓解的模式。这种模式只在支持MTE(内存标签
扩展)的arm64 CPU上工作,但它的内存和性能开销很低,因此可以在生产中使用。
硬件KASAN模式(#3)依赖硬件来执行检查,但仍需要支持内存标签指令的编译器
版本。GCC 10+和Clang 11+支持此模式。
关于每种KASAN模式的内存和性能影响的细节,请参见相应的Kconfig选项的描述。
两种软件KASAN模式都适用于SLUB和SLAB内存分配器,而基于硬件标签的KASAN目前
仅支持SLUB
通用模式和基于软件标签的模式通常被称为软件模式。基于软件标签的模式和基于
硬件标签的模式被称为基于标签的模式
目前x86_64、arm、arm64、xtensa、s390、riscv架构支持通用KASAN模式,仅
arm64架构支持基于标签的KASAN模式。
支持
----
体系架构
~~~~~~~~
在x86_64、arm、arm64、powerpc、riscv、s390和xtensa上支持通用KASAN,
而基于标签的KASAN模式只在arm64上支持。
编译器
~~~~~~
软件KASAN模式使用编译时工具在每个内存访问之前插入有效性检查,因此需要一个
提供支持的编译器版本。基于硬件标签的模式依靠硬件来执行这些检查,但仍然需要
一个支持内存标签指令的编译器版本。
通用KASAN需要GCC 8.3.0版本或更高版本,或者内核支持的任何Clang版本。
基于软件标签的KASAN需要GCC 11+或者内核支持的任何Clang版本。
基于硬件标签的KASAN需要GCC 10+或Clang 12+。
内存类型
~~~~~~~~
通用KASAN支持在所有的slab、page_alloc、vmap、vmalloc、堆栈和全局内存
中查找错误。
基于软件标签的KASAN支持slab、page_alloc、vmalloc和堆栈内存。
基于硬件标签的KASAN支持slab、page_alloc和不可执行的vmalloc内存。
对于slab,两种软件KASAN模式都支持SLUB和SLAB分配器,而基于硬件标签的
KASAN只支持SLUB。
用法
----
......@@ -53,7 +84,7 @@ arm64架构支持基于标签的KASAN模式。
对于软件模式,还可以在 ``CONFIG_KASAN_OUTLINE`` 和 ``CONFIG_KASAN_INLINE``
之间进行选择。outline和inline是编译器插桩类型。前者产生较小的二进制文件,
而后者快1.1-2倍。
而后者快2倍。
要将受影响的slab对象的alloc和free堆栈跟踪包含到报告中,请启用
``CONFIG_STACKTRACE`` 。要包括受影响物理页面的分配和释放堆栈跟踪的话,
......@@ -172,21 +203,29 @@ KASAN受通用 ``panic_on_warn`` 命令行参数的影响。启用该功能后
默认情况下,KASAN只为第一次无效内存访问打印错误报告。使用 ``kasan_multi_shot`` ,
KASAN会针对每个无效访问打印报告。这有效地禁用了KASAN报告的 ``panic_on_warn`` 。
另外,独立于 ``panic_on_warn`` , ``kasan.fault=`` 引导参数可以用来控制恐慌和报
告行为:
- ``kasan.fault=report`` 或 ``=panic`` 控制是只打印KASAN报告还是同时使内核恐慌
(默认: ``report`` )。即使启用了 ``kasan_multi_shot`` ,也会发生内核恐慌。
基于硬件标签的KASAN模式(请参阅下面有关各种模式的部分)旨在在生产中用作安全缓解
措施。因此,它支持允许禁用KASAN或控制其功能的引导参数。
措施。因此,它支持允许禁用KASAN或控制其功能的附加引导参数。
- ``kasan=off`` 或 ``=on`` 控制KASAN是否启用 (默认: ``on`` )。
- ``kasan.mode=sync`` 或 ``=async`` 控制KASAN是否配置为同步或异步执行模式(默认:
``sync`` )。同步模式:当标签检查错误发生时,立即检测到错误访问。异步模式:
延迟错误访问检测。当标签检查错误发生时,信息存储在硬件中(在arm64的
- ``kasan.mode=sync`` 、 ``=async`` 或 ``=asymm`` 控制KASAN是否配置
为同步或异步执行模式(默认:``sync`` )。
同步模式:当标签检查错误发生时,立即检测到错误访问。
异步模式:延迟错误访问检测。当标签检查错误发生时,信息存储在硬件中(在arm64的
TFSR_EL1寄存器中)。内核会定期检查硬件,并且仅在这些检查期间报告标签错误。
非对称模式:读取时同步检测不良访问,写入时异步检测。
- ``kasan.vmalloc=off`` 或 ``=on`` 禁用或启用vmalloc分配的标记(默认:``on`` )。
- ``kasan.stacktrace=off`` 或 ``=on`` 禁用或启用alloc和free堆栈跟踪收集
(默认: ``on`` )。
- ``kasan.fault=report`` 或 ``=panic`` 控制是只打印KASAN报告还是同时使内核恐慌
(默认: ``report`` )。即使启用了 ``kasan_multi_shot`` ,也会发生内核恐慌。
实施细则
--------
......@@ -244,7 +283,6 @@ KASAN会针对每个无效访问打印报告。这有效地禁用了KASAN报告
基于软件标签的KASAN使用0xFF作为匹配所有指针标签(不检查通过带有0xFF指针标签
的指针进行的访问)。值0xFE当前保留用于标记已释放的内存区域。
基于软件标签的KASAN目前仅支持对Slab和page_alloc内存进行标记。
基于硬件标签的KASAN模式
~~~~~~~~~~~~~~~~~~~~~~~
......@@ -262,8 +300,6 @@ KASAN会针对每个无效访问打印报告。这有效地禁用了KASAN报告
基于硬件标签的KASAN使用0xFF作为匹配所有指针标签(不检查通过带有0xFF指针标签的
指针进行的访问)。值0xFE当前保留用于标记已释放的内存区域。
基于硬件标签的KASAN目前仅支持对Slab和page_alloc内存进行标记。
如果硬件不支持MTE(ARMv8.5之前),则不会启用基于硬件标签的KASAN。在这种情况下,
所有KASAN引导参数都将被忽略。
......@@ -275,6 +311,8 @@ KASAN会针对每个无效访问打印报告。这有效地禁用了KASAN报告
影子内存
--------
本节的内容只适用于软件KASAN模式。
内核将内存映射到地址空间的几个不同部分。内核虚拟地址的范围很大:没有足够的真实
内存来支持内核可以访问的每个地址的真实影子区域。因此,KASAN只为地址空间的某些
部分映射真实的影子。
......@@ -297,7 +335,7 @@ CONFIG_KASAN_VMALLOC
~~~~~~~~~~~~~~~~~~~~
使用 ``CONFIG_KASAN_VMALLOC`` ,KASAN可以以更大的内存使用为代价覆盖vmalloc
空间。目前,这在x86、riscv、s390和powerpc上受支持。
空间。目前,这在arm64、x86、riscv、s390和powerpc上受支持。
这通过连接到vmalloc和vmap并动态分配真实的影子内存来支持映射。
......@@ -349,10 +387,10 @@ KASAN连接到vmap基础架构以懒清理未使用的影子内存。
``kasan_disable_current()``/``kasan_enable_current()`` 部分注释这部分代码。
这也会禁用通过函数调用发生的间接访问的报告。
对于基于标签的KASAN模式(包括硬件模式),要禁用访问检查,请使用
``kasan_reset_tag()`` 或 ``page_kasan_tag_reset()`` 。请注意,通过
``page_kasan_tag_reset()`` 临时禁用访问检查需要通过 ``page_kasan_tag``
/ ``page_kasan_tag_set`` 保存和恢复每页KASAN标签。
对于基于标签的KASAN模式,要禁用访问检查,请使用 ``kasan_reset_tag()`` 或
``page_kasan_tag_reset()`` 。请注意,通过 ``page_kasan_tag_reset()``
临时禁用访问检查需要通过 ``page_kasan_tag`` / ``page_kasan_tag_set`` 保
存和恢复每页KASAN标签。
测试
~~~~
......@@ -381,11 +419,10 @@ KASAN连接到vmap基础架构以懒清理未使用的影子内存。
当由于缺少KASAN报告而导致测试失败时::
# kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:629
Expected kasan_data->report_expected == kasan_data->report_found, but
kasan_data->report_expected == 1
kasan_data->report_found == 0
not ok 28 - kmalloc_double_kzfree
# kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:974
KASAN failure expected in "kfree_sensitive(ptr)", but none occurred
not ok 44 - kmalloc_double_kzfree
最后打印所有KASAN测试的累积状态。成功::
......
......@@ -106,3 +106,5 @@ __releases - 指定的锁在函数进入时被持有,但在退出时不被持
make 的可选变量 CHECKFLAGS 可以用来向 sparse 工具传递参数。编译系统会自
动向 sparse 工具传递 -Wbitwise 参数。
注意sparse定义了__CHECKER__预处理器符号。
\ No newline at end of file
......@@ -107,3 +107,28 @@ Documentation/dev-tools/kcov.rst 是能够构建在内核之中,用于在每
之后你就能确保这些错误在测试过程中都不会发生了。
一些工具与KUnit和kselftest集成,并且在检测到问题时会自动打断测试。
静态分析工具
============
除了测试运行中的内核,我们还可以使用**静态分析**工具直接分析内核的源代
码(**在编译时**)。内核中常用的工具允许人们检查整个源代码树或其中的特
定文件。它们使得在开发过程中更容易发现和修复问题。
Sparse可以通过执行类型检查、锁检查、值范围检查来帮助测试内核,此外还
可以在检查代码时报告各种错误和警告。关于如何使用它的细节,请参阅
Documentation/translations/zh_CN/dev-tools/sparse.rst。
Smatch扩展了Sparse,并提供了对编程逻辑错误的额外检查,如开关语句中
缺少断点,错误检查中未使用的返回值,忘记在错误路径的返回中设置错误代
码等。Smatch也有针对更严重问题的测试,如整数溢出、空指针解除引用和内
存泄漏。见项目页面http://smatch.sourceforge.net/。
Coccinelle是我们可以使用的另一个静态分析器。Coccinelle经常被用来
帮助源代码的重构和并行演化,但它也可以帮助避免常见代码模式中出现的某
些错误。可用的测试类型包括API测试、内核迭代器的正确使用测试、自由操
作的合理性检查、锁定行为的分析,以及已知的有助于保持内核使用一致性的
进一步测试。详情请见Documentation/dev-tools/coccinelle.rst。
不过要注意的是,静态分析工具存在**假阳性**的问题。在试图修复错误和警
告之前,需要仔细评估它们。
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/Devicetree/index.rst
:Original: Documentation/devicetree/index.rst
:翻译:
......
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/Devicetree/of_unittest.rst
:Original: Documentation/devicetree/of_unittest.rst
:翻译:
......
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/Devicetree/usage-model.rst
:Original: Documentation/devicetree/usage-model.rst
:翻译:
......
......@@ -14,7 +14,7 @@ Linux内核源文件可以包含kernel-doc格式的结构化文档注释,用
实际有着明显的不同。内核源包含成千上万个kernel-doc注释。请坚持遵循
此处描述的风格。
.. note:: kernel-doc无法包含Rust代码:请参考 Documentation/rust/docs.rst 。
.. note:: kernel-doc无法包含Rust代码:请参考 Documentation/rust/general-information.rst 。
从注释中提取kernel-doc结构,并从中生成适当的 `Sphinx C 域`_ 函数和带有锚点的
类型描述。这些注释将被过滤以生成特殊kernel-doc高亮和交叉引用。详见下文。
......
......@@ -37,10 +37,10 @@ configfs轻松配置的对象(例如:设备,触发器)。
3. 软件触发器
=============
IIO默认configfs组之一是“触发器”组。 挂载configfs后可以自动访问它,并且可
IIO默认configfs组之一是“触发器”组。挂载configfs后可以自动访问它,并且可
以在/config/iio/triggers下找到。
IIO软件触发器为创建多种触发器类型提供了支持。 通常在include/linux/iio
IIO软件触发器为创建多种触发器类型提供了支持。通常在include/linux/iio
/sw_trigger.h:中的接口下将新的触发器类型实现为单独的内核模块:
::
......@@ -76,10 +76,10 @@ IIO软件触发器为创建多种触发器类型提供了支持。 通常在incl
.ops = &iio_trig_sample_ops,
};
module_iio_sw_trigger_driver(iio_trig_sample);
module_iio_sw_trigger_driver(iio_trig_sample);
每种触发器类型在/config/iio/triggers下都有其自己的目录。 加载iio-trig-sample
模块将创建“ trig-sample”触发器类型目录/config/iio/triggers/trig-sample.
每种触发器类型在/config/iio/triggers下都有其自己的目录。加载iio-trig-sample
模块将创建“trig-sample”触发器类型目录/config/iio/triggers/trig-sample.
我们支持以下中断源(触发器类型)
......@@ -102,3 +102,5 @@ module_iio_sw_trigger_driver(iio_trig_sample);
----------------------------
"hrtimer”触发器类型没有来自/config dir的任何可配置属性。
它确实引入了触发目录的sampling_frequency属性。
该属性以Hz为单位设置轮询频率,精度为mHz。
\ No newline at end of file
......@@ -81,7 +81,7 @@
过硬件中断)的“软件中断”将运行( ``kernel/softirq.c`` )。
此处完成了许多真正的中断处理工作。在向SMP过渡的早期,只有“bottom halves下半
部”(BHs)机制,无法利用多个CPU的优势。在从那些一团糟的电脑切换过来后不久,
部”(BHs)机制,无法利用多个CPU的优势。在从那些一团糟的电脑切换过来后不久,
我们放弃了这个限制,转而使用“软中断”。
``include/linux/interrupt.h`` 列出了不同的软中断。定时器软中断是一个非常重要
......@@ -95,8 +95,7 @@
.. warning::
“tasklet”这个名字是误导性的:它们与“任务”无关,可能更多与当时
阿列克谢·库兹涅佐夫享用的糟糕伏特加有关。
“tasklet”这个名字是误导性的:它们与“任务”无关。
你可以使用 :c:func:`in_softirq()` 宏( ``include/linux/preempt.h`` )来确认
是否处于软中断(或子任务)中。
......@@ -247,7 +246,7 @@ Provide mechanism not policy”。
与 :c:func:`put_user()` 和 :c:func:`get_user()` 不同,它们返回未复制的
数据量(即0仍然意味着成功)。
【是的,这个愚蠢的接口真心让我尴尬。火爆的口水仗大概每年都会发生。
【是的,这个讨厌的接口真心让我尴尬。火爆的口水仗大概每年都会发生。
—— Rusty Russell】
这些函数可以隐式睡眠。它不应该在用户上下文之外调用(没有意义)、调用时禁用中断
......@@ -538,9 +537,9 @@ Documentation/core-api/symbol-namespaces.rst 。
Linus和其他开发人员有时会更改开发内核中的函数或结构体名称;这样做不仅是为了
让每个人都保持警惕,还反映了一个重大的更改(例如,不能再在打开中断的情况下
调用,或者执行额外的检查,或者不执行以前捕获的检查)。通常这会附带一个linux
内核邮件列表中相当全面的注释;请搜索存档以查看。简单地对文件进行全局替换通常
会让事情变得 **更糟** 。
调用,或者执行额外的检查,或者不执行以前捕获的检查)。通常这会附带发送一个
相当全面的注释到相应的内核邮件列表中;请搜索存档以查看。简单地对文件进行全局
替换通常只会让事情变得 **更糟** 。
初始化结构体成员
------------------
......@@ -610,7 +609,7 @@ C++
为了让你的东西更正式、补丁更整洁,还有一些工作要做:
- 搞清楚你在谁的地界儿上干活。查看源文件的顶部、 ``MAINTAINERS`` 文件以及
- 搞清楚你修改的代码属于谁。查看源文件的根目录、 ``MAINTAINERS`` 文件以及
``CREDITS`` 文件的最后一部分。你应该和此人协调,确保你没有重新发明轮子,
或者尝试一些已经被拒绝的东西。
......@@ -629,12 +628,12 @@ C++
“obj-$(CONFIG_xxx) += xxx.o”。语法记录在
Documentation/kbuild/makefiles.rst 。
- 如果你做了一些有意义的事情,那可以把自己放进 ``CREDITS`` ,通常不止一个
文件(无论如何你的名字都应该在源文件的顶部)。维护人员意味着您希望在对
子系统进行更改时得到询问,并了解缺陷;这意味着对某部分代码做出更多承诺。
- 如果你认为自己做了一些有意义的事情,可以把自己放进 ``CREDITS`` ,通常不
止一个文件(无论如何你的名字都应该在源文件的顶部)。 ``MAINTAINERS``
意味着您希望在对子系统进行更改时得到询问,并了解缺陷;这意味着对某部分
代码做出更多承诺。
- 最后,别忘记去阅读 Documentation/process/submitting-patches.rst ,
也许还有 Documentation/process/submitting-drivers.rst 。
- 最后,别忘记去阅读 Documentation/process/submitting-patches.rst。
Kernel 仙女棒
===============
......
......@@ -14,17 +14,18 @@
.. toctree::
:maxdepth: 1
mutex-design
spinlocks
TODOList:
* locktypes
* lockdep-design
* lockstat
* locktorture
* mutex-design
* rt-mutex-design
* rt-mutex
* seqlock
* spinlocks
* ww-mutex-design
* preempt-locking
* pi-futex
......
.. SPDX-License-Identifier: GPL-2.0
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/locking/mutex-design.rst
:翻译:
唐艺舟 Tang Yizhou <tangyeechou@gmail.com>
================
通用互斥锁子系统
================
:初稿:
Ingo Molnar <mingo@redhat.com>
:更新:
Davidlohr Bueso <davidlohr@hp.com>
什么是互斥锁?
--------------
在Linux内核中,互斥锁(mutex)指的是一个特殊的加锁原语,它在共享内存系统上
强制保证序列化,而不仅仅是指在学术界或类似的理论教科书中出现的通用术语“相互
排斥”。互斥锁是一种睡眠锁,它的行为类似于二进制信号量(semaphores),在
2006年被引入时[1],作为后者的替代品。这种新的数据结构提供了许多优点,包括更
简单的接口,以及在当时更少的代码量(见缺陷)。
[1] https://lwn.net/Articles/164802/
实现
----
互斥锁由“struct mutex”表示,在include/linux/mutex.h中定义,并在
kernel/locking/mutex.c中实现。这些锁使用一个原子变量(->owner)来跟踪
它们生命周期内的锁状态。字段owner实际上包含的是指向当前锁所有者的
`struct task_struct *` 指针,因此如果无人持有锁,则它的值为空(NULL)。
由于task_struct的指针至少按L1_CACHE_BYTES对齐,低位(3)被用来存储额外
的状态(例如,等待者列表非空)。在其最基本的形式中,它还包括一个等待队列和
一个确保对其序列化访问的自旋锁。此外,CONFIG_MUTEX_SPIN_ON_OWNER=y的
系统使用一个自旋MCS锁(->osq,译注:MCS是两个人名的合并缩写),在下文的
(ii)中描述。
准备获得一把自旋锁时,有三种可能经过的路径,取决于锁的状态:
(i) 快速路径:试图通过调用cmpxchg()修改锁的所有者为当前任务,以此原子化地
获取锁。这只在无竞争的情况下有效(cmpxchg()检查值是否为0,所以3个状态
比特必须为0)。如果锁处在竞争状态,代码进入下一个可能的路径。
(ii) 中速路径:也就是乐观自旋,当锁的所有者正在运行并且没有其它优先级更高的
任务(need_resched,需要重新调度)准备运行时,当前任务试图自旋来获得
锁。原理是,如果锁的所有者正在运行,它很可能不久就会释放锁。互斥锁自旋体
使用MCS锁排队,这样只有一个自旋体可以竞争互斥锁。
MCS锁(由Mellor-Crummey和Scott提出)是一个简单的自旋锁,它具有一些
理想的特性,比如公平,以及每个CPU在试图获得锁时在一个本地变量上自旋。
它避免了常见的“检测-设置”自旋锁实现导致的(CPU核间)缓存行回弹
(cacheline bouncing)这种昂贵的开销。一个类MCS锁是为实现睡眠锁的
乐观自旋而专门定制的。这种定制MCS锁的一个重要特性是,它有一个额外的属性,
当自旋体需要重新调度时,它们能够退出MCS自旋锁队列。这进一步有助于避免
以下场景:需要重新调度的MCS自旋体将继续自旋等待自旋体所有者,即将获得
MCS锁时却直接进入慢速路径。
(iii) 慢速路径:最后的手段,如果仍然无法获得锁,该任务会被添加到等待队列中,
休眠直到被解锁路径唤醒。在通常情况下,它以TASK_UNINTERRUPTIBLE状态
阻塞。
虽然从形式上看,内核互斥锁是可睡眠的锁,路径(ii)使它实际上成为混合类型。通过
简单地不中断一个任务并忙着等待几个周期,而不是立即睡眠,这种锁已经被认为显著
改善一些工作负载的性能。注意,这种技术也被用于读写信号量(rw-semaphores)。
语义
----
互斥锁子系统检查并强制执行以下规则:
- 每次只有一个任务可以持有该互斥锁。
- 只有锁的所有者可以解锁该互斥锁。
- 不允许多次解锁。
- 不允许递归加锁/解锁。
- 互斥锁只能通过API进行初始化(见下文)。
- 一个任务不能在持有互斥锁的情况下退出。
- 持有锁的内存区域不得被释放。
- 被持有的锁不能被重新初始化。
- 互斥锁不能用于硬件或软件中断上下文,如小任务(tasklet)和定时器。
当CONFIG DEBUG_MUTEXES被启用时,这些语义将被完全强制执行。此外,互斥锁
调试代码还实现了一些其它特性,使锁的调试更容易、更快速:
- 当打印到调试输出时,总是使用互斥锁的符号名称。
- 加锁点跟踪,函数名符号化查找,系统持有的全部锁的列表,打印出它们。
- 所有者跟踪。
- 检测自我递归的锁并打印所有相关信息。
- 检测多任务环形依赖死锁,并打印所有受影响的锁和任务(并且只限于这些任务)。
接口
----
静态定义互斥锁::
DEFINE_MUTEX(name);
动态初始化互斥锁::
mutex_init(mutex);
以不可中断方式(uninterruptible)获取互斥锁::
void mutex_lock(struct mutex *lock);
void mutex_lock_nested(struct mutex *lock, unsigned int subclass);
int mutex_trylock(struct mutex *lock);
以可中断方式(interruptible)获取互斥锁::
int mutex_lock_interruptible_nested(struct mutex *lock,
unsigned int subclass);
int mutex_lock_interruptible(struct mutex *lock);
当原子变量减为0时,以可中断方式(interruptible)获取互斥锁::
int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
释放互斥锁::
void mutex_unlock(struct mutex *lock);
检测是否已经获取互斥锁::
int mutex_is_locked(struct mutex *lock);
缺陷
----
与它最初的设计和目的不同,'struct mutex' 是内核中最大的锁之一。例如:在
x86-64上它是32字节,而 'struct semaphore' 是24字节,rw_semaphore是
40字节。更大的结构体大小意味着更多的CPU缓存和内存占用。
何时使用互斥锁
--------------
总是优先选择互斥锁而不是任何其它锁原语,除非互斥锁的严格语义不合适,和/或临界区
阻止锁被共享。
......@@ -19,8 +19,7 @@
内核开发社区已经发展出一套用于发布补丁的约定和过程;遵循这些约定和过程将使
参与其中的每个人的生活更加轻松。本文档试图描述这些约定的部分细节;更多信息
也可在以下文档中找到
:ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`,
:ref:`Documentation/translations/zh_CN/process/submitting-drivers.rst <cn_submittingdrivers>`
:ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`
和 :ref:`Documentation/translations/zh_CN/process/submit-checklist.rst <cn_submitchecklist>`。
何时寄送
......
......@@ -19,7 +19,6 @@
:ref:`Documentation/translations/zh_CN/process/howto.rst <cn_process_howto>`
文件是一个重要的起点;
:ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`
和 :ref:`Documentation/translations/zh_CN/process/submitting-drivers.rst <cn_submittingdrivers>`
也是所有内核开发人员都应该阅读的内容。许多内部内核API都是使用kerneldoc机制
记录的;“make htmldocs”或“make pdfdocs”可用于以HTML或PDF格式生成这些文档
(尽管某些发行版提供的tex版本会遇到内部限制,无法正确处理文档)。
......
......@@ -96,7 +96,6 @@ Linux内核代码中包含有大量的文档。这些文档对于学习如何与
的代码。
:ref:`Documentation/translations/zh_CN/process/submitting-patches.rst <cn_submittingpatches>`
:ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
这两份文档明确描述如何创建和发送补丁,其中包括(但不仅限于):
- 邮件内容
......
......@@ -40,7 +40,6 @@
.. toctree::
:maxdepth: 1
submitting-drivers
submit-checklist
stable-api-nonsense
stable-kernel-rules
......
.. _cn_submittingdrivers:
.. include:: ../disclaimer-zh_CN.rst
:Original: :ref:`Documentation/process/submitting-drivers.rst
<submittingdrivers>`
如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者::
中文版维护者: 李阳 Li Yang <leoyang.li@nxp.com>
中文版翻译者: 李阳 Li Yang <leoyang.li@nxp.com>
中文版校译者: 陈琦 Maggie Chen <chenqi@beyondsoft.com>
王聪 Wang Cong <xiyou.wangcong@gmail.com>
张巍 Zhang Wei <wezhang@outlook.com>
如何向 Linux 内核提交驱动程序
=============================
这篇文档将会解释如何向不同的内核源码树提交设备驱动程序。请注意,如果你感
兴趣的是显卡驱动程序,你也许应该访问 XFree86 项目(https://www.xfree86.org/)
和/或 X.org 项目 (https://x.org)。
另请参阅 Documentation/translations/zh_CN/process/submitting-patches.rst 文档。
分配设备号
----------
块设备和字符设备的主设备号与从设备号是由 Linux 命名编号分配权威 LANANA(
现在是 Torben Mathiasen)负责分配。申请的网址是 https://www.lanana.org/。
即使不准备提交到主流内核的设备驱动也需要在这里分配设备号。有关详细信息,
请参阅 Documentation/admin-guide/devices.rst。
如果你使用的不是已经分配的设备号,那么当你提交设备驱动的时候,它将会被强
制分配一个新的设备号,即便这个设备号和你之前发给客户的截然不同。
设备驱动的提交对象
------------------
Linux 2.0:
此内核源码树不接受新的驱动程序。
Linux 2.2:
此内核源码树不接受新的驱动程序。
Linux 2.4:
如果所属的代码领域在内核的 MAINTAINERS 文件中列有一个总维护者,
那么请将驱动程序提交给他。如果此维护者没有回应或者你找不到恰当的
维护者,那么请联系 Willy Tarreau <w@1wt.eu>。
Linux 2.6:
除了遵循和 2.4 版内核同样的规则外,你还需要在 linux-kernel 邮件
列表上跟踪最新的 API 变化。向 Linux 2.6 内核提交驱动的顶级联系人
是 Andrew Morton <akpm@linux-foundation.org>。
决定设备驱动能否被接受的条件
----------------------------
许可: 代码必须使用 GNU 通用公开许可证 (GPL) 提交给 Linux,但是
我们并不要求 GPL 是唯一的许可。你或许会希望同时使用多种
许可证发布,如果希望驱动程序可以被其他开源社区(比如BSD)
使用。请参考 include/linux/module.h 文件中所列出的可被
接受共存的许可。
版权: 版权所有者必须同意使用 GPL 许可。最好提交者和版权所有者
是相同个人或实体。否则,必需列出授权使用 GPL 的版权所有
人或实体,以备验证之需。
接口: 如果你的驱动程序使用现成的接口并且和其他同类的驱动程序行
为相似,而不是去发明无谓的新接口,那么它将会更容易被接受。
如果你需要一个 Linux 和 NT 的通用驱动接口,那么请在用
户空间实现它。
代码: 请使用 Documentation/process/coding-style.rst 中所描述的 Linux 代码风
格。如果你的某些代码段(例如那些与 Windows 驱动程序包共
享的代码段)需要使用其他格式,而你却只希望维护一份代码,
那么请将它们很好地区分出来,并且注明原因。
可移植性: 请注意,指针并不永远是 32 位的,不是所有的计算机都使用小
尾模式 (little endian) 存储数据,不是所有的人都拥有浮点
单元,不要随便在你的驱动程序里嵌入 x86 汇编指令。只能在
x86 上运行的驱动程序一般是不受欢迎的。虽然你可能只有 x86
硬件,很难测试驱动程序在其他平台上是否可用,但是确保代码
可以被轻松地移植却是很简单的。
清晰度: 做到所有人都能修补这个驱动程序将会很有好处,因为这样你将
会直接收到修复的补丁而不是 bug 报告。如果你提交一个试图
隐藏硬件工作机理的驱动程序,那么它将会被扔进废纸篓。
电源管理: 因为 Linux 正在被很多移动设备和桌面系统使用,所以你的驱
动程序也很有可能被使用在这些设备上。它应该支持最基本的电
源管理,即在需要的情况下实现系统级休眠和唤醒要用到的
.suspend 和 .resume 函数。你应该检查你的驱动程序是否能正
确地处理休眠与唤醒,如果实在无法确认,请至少把 .suspend
函数定义成返回 -ENOSYS(功能未实现)错误。你还应该尝试确
保你的驱动在什么都不干的情况下将耗电降到最低。要获得驱动
程序测试的指导,请参阅
Documentation/power/drivers-testing.rst。有关驱动程序电
源管理问题相对全面的概述,请参阅
Documentation/driver-api/pm/devices.rst。
管理: 如果一个驱动程序的作者还在进行有效的维护,那么通常除了那
些明显正确且不需要任何检查的补丁以外,其他所有的补丁都会
被转发给作者。如果你希望成为驱动程序的联系人和更新者,最
好在代码注释中写明并且在 MAINTAINERS 文件中加入这个驱动
程序的条目。
不影响设备驱动能否被接受的条件
------------------------------
供应商: 由硬件供应商来维护驱动程序通常是一件好事。不过,如果源码
树里已经有其他人提供了可稳定工作的驱动程序,那么请不要期
望“我是供应商”会成为内核改用你的驱动程序的理由。理想的情
况是:供应商与现有驱动程序的作者合作,构建一个统一完美的
驱动程序。
作者: 驱动程序是由大的 Linux 公司研发还是由你个人编写,并不影
响其是否能被内核接受。没有人对内核源码树享有特权。只要你
充分了解内核社区,你就会发现这一点。
资源列表
--------
Linux 内核主源码树:
ftp.??.kernel.org:/pub/linux/kernel/...
?? == 你的国家代码,例如 "cn"、"us"、"uk"、"fr" 等等
Linux 内核邮件列表:
linux-kernel@vger.kernel.org
[可通过向majordomo@vger.kernel.org发邮件来订阅]
Linux 设备驱动程序,第三版(探讨 2.6.10 版内核):
https://lwn.net/Kernel/LDD3/ (免费版)
LWN.net:
每周内核开发活动摘要 - https://lwn.net/
2.6 版中 API 的变更:
https://lwn.net/Articles/2.6-kernel-api/
将旧版内核的驱动程序移植到 2.6 版:
https://lwn.net/Articles/driver-porting/
内核新手(KernelNewbies):
为新的内核开发者提供文档和帮助
https://kernelnewbies.org/
Linux USB项目:
http://www.linux-usb.org/
写内核驱动的“不要”(Arjan van de Ven著):
http://www.fenrus.org/how-to-not-write-a-device-driver-paper.pdf
内核清洁工 (Kernel Janitor):
https://kernelnewbies.org/KernelJanitors
......@@ -23,9 +23,7 @@
以下文档含有大量简洁的建议, 具体请见:
:ref:`Documentation/process <development_process_main>`
同样,:ref:`Documentation/translations/zh_CN/process/submit-checklist.rst <cn_submitchecklist>`
给出在提交代码前需要检查的项目的列表。如果你在提交一个驱动程序,那么
同时阅读一下:
:ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>`
给出在提交代码前需要检查的项目的列表。
其中许多步骤描述了Git版本控制系统的默认行为;如果您使用Git来准备补丁,
您将发现它为您完成的大部分机械工作,尽管您仍然需要准备和记录一组合理的
......
......@@ -19,7 +19,6 @@ RISC-V 体系结构
boot-image-header
vm-layout
pmu
patch-acceptance
......
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/riscv/pmu.rst
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
.. _cn_riscv_pmu:
========================
RISC-V平台上对PMUs的支持
========================
Alan Kao <alankao@andestech.com>, Mar 2018
简介
------------
截止本文撰写时,在The RISC-V ISA Privileged Version 1.10中提到的 perf_event
相关特性如下:
(详情请查阅手册)
* [m|s]counteren
* mcycle[h], cycle[h]
* minstret[h], instret[h]
* mhpeventx, mhpcounterx[h]
仅有以上这些功能,移植perf需要做很多工作,究其原因是缺少以下通用架构的性能
监测特性:
* 启用/停用计数器
在我们这里,计数器一直在自由运行。
* 计数器溢出引起的中断
规范中没有这种功能。
* 中断指示器
不可能所有的计数器都有很多的中断端口,所以需要一个中断指示器让软件来判断
哪个计数器刚好溢出。
* 写入计数器
由于内核不能修改计数器,所以会有一个SBI来支持这个功能[1]。 另外,一些厂商
考虑实现M-S-U型号机器的硬件扩展来直接写入计数器。
这篇文档旨在为开发者提供一个在内核中支持PMU的简要指南。下面的章节简要解释了
perf' 机制和待办事项。
你可以在这里查看以前的讨论[1][2]。 另外,查看附录中的相关内核结构体可能会有
帮助。
1. 初始化
---------
*riscv_pmu* 是一个类型为 *struct riscv_pmu* 的全局指针,它包含了根据perf内部
约定的各种方法和PMU-specific参数。人们应该声明这样的实例来代表PMU。 默认情况
下, *riscv_pmu* 指向一个常量结构体 *riscv_base_pmu* ,它对基准QEMU模型有非常
基础的支持。
然后他/她可以将实例的指针分配给 *riscv_pmu* ,这样就可以利用已经实现的最小逻
辑,或者创建他/她自己的 *riscv_init_platform_pmu* 实现。
换句话说,现有的 *riscv_base_pmu* 源只是提供了一个参考实现。 开发者可以灵活地
决定多少部分可用,在最极端的情况下,他们可以根据自己的需要定制每一个函数。
2. Event Initialization
-----------------------
当用户启动perf命令来监控一些事件时,首先会被用户空间的perf工具解释为多个
*perf_event_open* 系统调用,然后进一步调用上一步分配的 *event_init* 成员函数
的主体。 在 *riscv_base_pmu* 的情况下,就是 *riscv_event_init* 。
该功能的主要目的是将用户提供的事件翻译成映射图,从而可以直接对HW-related的控
制寄存器或计数器进行操作。该翻译基于 *riscv_pmu* 中提供的映射和方法。
注意,有些功能也可以在这个阶段完成:
(1) 中断设置,这个在下一节说;
(2) 特限级设置(仅用户空间、仅内核空间、两者都有);
(3) 析构函数设置。 通常应用 *riscv_destroy_event* 即可;
(4) 对非采样事件的调整,这将被函数应用,如 *perf_adjust_period* ,通常如下::
if (!is_sampling_event(event)) {
hwc->sample_period = x86_pmu.max_period;
hwc->last_period = hwc->sample_period;
local64_set(&hwc->period_left, hwc->sample_period);
}
在 *riscv_base_pmu* 的情况下,目前只提供了(3)。
3. 中断
-------
3.1. 中断初始化
这种情况经常出现在 *event_init* 方案的开头。通常情况下,这应该是一个代码段,如::
int x86_reserve_hardware(void)
{
int err = 0;
if (!atomic_inc_not_zero(&pmc_refcount)) {
mutex_lock(&pmc_reserve_mutex);
if (atomic_read(&pmc_refcount) == 0) {
if (!reserve_pmc_hardware())
err = -EBUSY;
else
reserve_ds_buffers();
}
if (!err)
atomic_inc(&pmc_refcount);
mutex_unlock(&pmc_reserve_mutex);
}
return err;
}
而神奇的是 *reserve_pmc_hardware* ,它通常做原子操作,使实现的IRQ可以从某个全局函
数指针访问。 而 *release_pmc_hardware* 的作用正好相反,它用在上一节提到的事件分配
器中。
(注:从所有架构的实现来看,*reserve/release* 对总是IRQ设置,所以 *pmc_hardware*
似乎有些误导。 它并不处理事件和物理计数器之间的绑定,这一点将在下一节介绍。)
3.2. IRQ结构体
基本上,一个IRQ运行以下伪代码::
for each hardware counter that triggered this overflow
get the event of this counter
// following two steps are defined as *read()*,
// check the section Reading/Writing Counters for details.
count the delta value since previous interrupt
update the event->count (# event occurs) by adding delta, and
event->hw.period_left by subtracting delta
if the event overflows
sample data
set the counter appropriately for the next overflow
if the event overflows again
too frequently, throttle this event
fi
fi
end for
然而截至目前,没有一个RISC-V的实现为perf设计了中断,所以具体的实现要在未来完成。
4. Reading/Writing 计数
-----------------------
它们看似差不多,但perf对待它们的态度却截然不同。 对于读,在 *struct pmu* 中有一个
*read* 接口,但它的作用不仅仅是读。 根据上下文,*read* 函数不仅要读取计数器的内容
(event->count),还要更新左周期到下一个中断(event->hw.period_left)。
但 perf 的核心不需要直接写计数器。 写计数器隐藏在以下两点的抽象化之后,
1) *pmu->start* ,从字面上看就是开始计数,所以必须把计数器设置成一个合适的值,以
便下一次中断;
2)在IRQ里面,应该把计数器设置成同样的合理值。
在RISC-V中,读操作不是问题,但写操作就需要费些力气了,因为S模式不允许写计数器。
5. add()/del()/start()/stop()
-----------------------------
基本思想: add()/del() 向PMU添加/删除事件,start()/stop() 启动/停止PMU中某个事件
的计数器。 所有这些函数都使用相同的参数: *struct perf_event *event* 和 *int flag* 。
把 perf 看作一个状态机,那么你会发现这些函数作为这些状态之间的状态转换过程。
定义了三种状态(event->hw.state):
* PERF_HES_STOPPED: 计数停止
* PERF_HES_UPTODATE: event->count是最新的
* PERF_HES_ARCH: 依赖于体系结构的用法,。。。我们现在并不需要它。
这些状态转换的正常流程如下:
* 用户启动一个 perf 事件,导致调用 *event_init* 。
* 当被上下文切换进来的时候,*add* 会被 perf core 调用,并带有一个标志 PERF_EF_START,
也就是说事件被添加后应该被启动。 在这个阶段,如果有的话,一般事件会被绑定到一个物
理计数器上。当状态变为PERF_HES_STOPPED和PERF_HES_UPTODATE,因为现在已经停止了,
(软件)事件计数不需要更新。
- 然后调用 *start* ,并启用计数器。
通过PERF_EF_RELOAD标志,它向计数器写入一个适当的值(详细情况请参考上一节)。
如果标志不包含PERF_EF_RELOAD,则不会写入任何内容。
现在状态被重置为none,因为它既没有停止也没有更新(计数已经开始)。
*当被上下文切换出来时被调用。 然后,它检查出PMU中的所有事件,并调用 *stop* 来更新它们
的计数。
- *stop* 被 *del* 和perf核心调用,标志为PERF_EF_UPDATE,它经常以相同的逻辑和 *read*
共用同一个子程序。
状态又一次变为PERF_HES_STOPPED和PERF_HES_UPTODATE。
- 这两对程序的生命周期: *add* 和 *del* 在任务切换时被反复调用;*start* 和 *stop* 在
perf核心需要快速停止和启动时也会被调用,比如在调整中断周期时。
目前的实现已经足够了,将来可以很容易地扩展到功能。
A. 相关结构体
-------------
* struct pmu: include/linux/perf_event.h
* struct riscv_pmu: arch/riscv/include/asm/perf_event.h
两个结构体都被设计为只读。
*struct pmu* 定义了一些函数指针接口,它们大多以 *struct perf_event* 作为主参数,根据
perf的内部状态机处理perf事件(详情请查看kernel/events/core.c)。
*struct riscv_pmu* 定义了PMU的具体参数。 命名遵循所有其它架构的惯例。
* struct perf_event: include/linux/perf_event.h
* struct hw_perf_event
表示 perf 事件的通用结构体,以及硬件相关的细节。
* struct riscv_hw_events: arch/riscv/include/asm/perf_event.h
保存事件状态的结构有两个固定成员。
事件的数量和事件的数组。
参考文献
--------
[1] https://github.com/riscv/riscv-linux/pull/124
[2] https://groups.google.com/a/groups.riscv.org/forum/#!topic/sw-dev/f19TmCNP6yA
......@@ -6,6 +6,7 @@
:翻译:
司延腾 Yanteng Si <siyanteng@loongson.cn>
Binbin Zhou <zhoubinbin@loongson.cn>
============================
RISC-V Linux上的虚拟内存布局
......@@ -65,3 +66,39 @@ RISC-V Linux Kernel SV39
ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
__________________|____________|__________________|_________|____________________________________________________________
RISC-V Linux Kernel SV48
------------------------
::
========================================================================================================================
开始地址 | 偏移 | 结束地址 | 大小 | 虚拟内存区域描述
========================================================================================================================
| | | |
0000000000000000 | 0 | 00007fffffffffff | 128 TB | 用户空间虚拟内存,每个内存管理器不同
__________________|____________|__________________|_________|___________________________________________________________
| | | |
0000800000000000 | +128 TB | ffff7fffffffffff | ~16M TB | ... 巨大的、几乎64位宽的直到内核映射的-128TB地方
| | | | 开始偏移的非经典虚拟内存地址空洞。
| | | |
__________________|____________|__________________|_________|___________________________________________________________
|
| 内核空间的虚拟内存,在所有进程之间共享:
____________________________________________________________|___________________________________________________________
| | | |
ffff8d7ffee00000 | -114.5 TB | ffff8d7ffeffffff | 2 MB | fixmap
ffff8d7fff000000 | -114.5 TB | ffff8d7fffffffff | 16 MB | PCI io
ffff8d8000000000 | -114.5 TB | ffff8f7fffffffff | 2 TB | vmemmap
ffff8f8000000000 | -112.5 TB | ffffaf7fffffffff | 32 TB | vmalloc/ioremap space
ffffaf8000000000 | -80.5 TB | ffffef7fffffffff | 64 TB | 直接映射所有物理内存
ffffef8000000000 | -16.5 TB | fffffffeffffffff | 16.5 TB | kasan
__________________|____________|__________________|_________|____________________________________________________________
|
| 从此处开始,与39-bit布局相同:
____________________________________________________________|____________________________________________________________
| | | |
ffffffff00000000 | -4 GB | ffffffff7fffffff | 2 GB | modules, BPF
ffffffff80000000 | -2 GB | ffffffffffffffff | 2 GB | kernel
__________________|____________|__________________|_________|____________________________________________________________
......@@ -57,8 +57,8 @@ cpu<N> 1 2 3 4 5 6 7 8 9
接下来的三个统计数据描述了调度延迟:
7) 本处理器运行任务的总时间,单位是jiffies
8) 本处理器任务等待运行的时间,单位是jiffies
7) 本处理器运行任务的总时间,单位是纳秒
8) 本处理器任务等待运行的时间,单位是纳秒
9) 本CPU运行了#个时间片
域统计数据
......@@ -146,8 +146,8 @@ domain<N> <cpumask> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
schedstats还添加了一个新的/proc/<pid>/schedstat文件,来提供一些进程级的
相同信息。这个文件中,有三个字段与该进程相关:
1) 在CPU上运行花费的时间
2) 在运行队列上等待的时间
1) 在CPU上运行花费的时间(单位是纳秒)
2) 在运行队列上等待的时间(单位是纳秒)
3) 在CPU上运行了#个时间片
可以很容易地编写一个程序,利用这些额外的字段来报告一个特定的进程或一组进程在
......
.. include:: ../disclaimer-zh_CN.rst
:Original: Documentation/vm/_free_page_reporting.rst
:Original: Documentation/vm/free_page_reporting.rst
:翻译:
......
:Original: Documentation/vm/_free_page_reporting.rst
:Original: Documentation/vm/free_page_reporting.rst
:翻译:
......
......@@ -50,55 +50,55 @@
临时虚拟映射
============
内核包含几种创建临时映射的方法。:
内核包含几种创建临时映射的方法。下面的列表按照使用的优先顺序显示了它们。
* vmap(). 这可以用来将多个物理页长期映射到一个连续的虚拟空间。它需要synchronization
来解除映射
* kmap_local_page()。这个函数是用来要求短期映射的。它可以从任何上下文(包括中断)中调用,
但是映射只能在获取它们的上下文中使用
* kmap(). 这允许对单个页面进行短期映射。它需要synchronization,但在一定程度上被摊销。
当以嵌套方式使用时,它也很容易出现死锁,因此不建议在新代码中使用它。
在可行的情况下,这个函数应该比其他所有的函数优先使用。
* kmap_atomic(). 这允许对单个页面进行非常短的时间映射。由于映射被限制在发布它的CPU上,
它表现得很好,但发布任务因此被要求留在该CPU上直到它完成,以免其他任务取代它的映射。
kmap_atomic() 也可以由中断上下文使用,因为它不睡眠,而且调用者可能在调用kunmap_atomic()
之后才睡眠。
可以假设k[un]map_atomic()不会失败。
这些映射是线程本地和CPU本地的,这意味着映射只能从这个线程中访问,并且当映射处于活动状
态时,该线程与CPU绑定。即使线程被抢占了(因为抢占永远不会被函数禁用),CPU也不能通过
CPU-hotplug从系统中拔出,直到映射被处理掉。
在本地的kmap区域中采取pagefaults是有效的,除非获取本地映射的上下文由于其他原因不允许
这样做。
使用kmap_atomic
===============
kmap_local_page()总是返回一个有效的虚拟地址,并且假定kunmap_local()不会失败。
何时何地使用 kmap_atomic() 是很直接的。当代码想要访问一个可能从高内存(见__GFP_HIGHMEM)
分配的页面的内容时,例如在页缓存中的页面,就会使用它。该API有两个函数,它们的使用方式与
下面类似::
嵌套kmap_local_page()和kmap_atomic()映射在一定程度上是允许的(最多到KMAP_TYPE_NR),
但是它们的调用必须严格排序,因为映射的实现是基于堆栈的。关于如何管理嵌套映射的细节,
请参见kmap_local_page() kdocs(包含在 "函数 "部分)。
/* 找到感兴趣的页面。 */
struct page *page = find_get_page(mapping, offset);
/* 获得对该页内容的访问权。 */
void *vaddr = kmap_atomic(page);
* kmap_atomic(). 这允许对单个页面进行非常短的时间映射。由于映射被限制在发布它的CPU上,
它表现得很好,但发布的任务因此被要求留在该CPU上直到它完成,以免其他任务取代它的映射。
/* 对该页的内容做一些处理。 */
memset(vaddr, 0, PAGE_SIZE);
kmap_atomic()也可以被中断上下文使用,因为它不睡眠,调用者也可能在调用kunmap_atomic()
后才睡眠。
/* 解除该页面的映射。 */
kunmap_atomic(vaddr);
内核中对kmap_atomic()的每次调用都会创建一个不可抢占的段,并禁用缺页异常。这可能是
未预期延迟的来源之一。因此用户应该选择kmap_local_page()而不是kmap_atomic()。
注意,kunmap_atomic()调用的是kmap_atomic()调用的结果而不是参数
假设k[un]map_atomic()不会失败
如果你需要映射两个页面,因为你想从一个页面复制到另一个页面,你需要保持kmap_atomic调用严
格嵌套,如::
* kmap()。这应该被用来对单个页面进行短时间的映射,对抢占或迁移没有限制。它会带来开销,
因为映射空间是受限制的,并且受到全局锁的保护,以实现同步。当不再需要映射时,必须用
kunmap()释放该页被映射的地址。
vaddr1 = kmap_atomic(page1);
vaddr2 = kmap_atomic(page2);
映射变化必须广播到所有CPU(核)上,kmap()还需要在kmap的池被回绕(TLB项用光了,需要从第
一项复用)时进行全局TLB无效化,当映射空间被完全利用时,它可能会阻塞,直到有一个可用的
槽出现。因此,kmap()只能从可抢占的上下文中调用。
memcpy(vaddr1, vaddr2, PAGE_SIZE);
如果一个映射必须持续相对较长的时间,上述所有的工作都是必要的,但是内核中大部分的
高内存映射都是短暂的,而且只在一个地方使用。这意味着在这种情况下,kmap()的成本大
多被浪费了。kmap()并不是为长期映射而设计的,但是它已经朝着这个方向发展了,在较新
的代码中强烈不鼓励使用它,前面的函数集应该是首选。
kunmap_atomic(vaddr2);
kunmap_atomic(vaddr1);
在64位系统中,调用kmap_local_page()、kmap_atomic()和kmap()没有实际作用,因为64位
地址空间足以永久映射所有物理内存页面。
* vmap()。这可以用来将多个物理页长期映射到一个连续的虚拟空间。它需要全局同步来解除
映射。
临时映射的成本
==============
......@@ -126,3 +126,12 @@ i386 PAE
一般的建议是,你不要在32位机器上使用超过8GiB的空间--尽管更多的空间可能对你和你的工作
量有用,但你几乎是靠你自己--不要指望内核开发者真的会很关心事情的进展情况。
函数
====
该API在以下内核代码中:
include/linux/highmem.h
include/linux/highmem-internal.h
......@@ -12,11 +12,27 @@
Linux内存管理文档
=================
这是一个关于Linux内存管理(mm)子系统内部的文档集,其中有不同层次的细节,包括注释
和邮件列表的回复,用于阐述数据结构和算法的基本情况。如果你正在寻找关于简单分配内存的建
议,请参阅(Documentation/translations/zh_CN/core-api/memory-allocation.rst)。
对于控制和调整指南,请参阅(Documentation/admin-guide/mm/index)。
TODO:待引用文档集被翻译完毕后请及时修改此处)
这是一份关于了解Linux的内存管理子系统的指南。如果你正在寻找关于简单分配内存的
建议,请参阅内存分配指南
(Documentation/translations/zh_CN/core-api/memory-allocation.rst)。
关于控制和调整的指南,请看管理指南
(Documentation/translations/zh_CN/admin-guide/mm/index.rst)。
.. toctree::
:maxdepth: 1
highmem
该处剩余文档待原始文档有内容后翻译。
遗留文档
========
这是一个关于Linux内存管理(MM)子系统内部的旧文档的集合,其中有不同层次的细节,
包括注释和邮件列表的回复,用于阐述数据结构和算法的描述。它应该被很好地整合到上述
结构化的文档中,如果它已经完成了它的使命,可以删除。
.. toctree::
:maxdepth: 1
......@@ -25,7 +41,6 @@ TODO:待引用文档集被翻译完毕后请及时修改此处)
balance
damon/index
free_page_reporting
highmem
ksm
frontswap
hmm
......@@ -36,10 +51,12 @@ TODO:待引用文档集被翻译完毕后请及时修改此处)
numa
overcommit-accounting
page_frags
page_migration
page_owner
page_table_check
remap_file_pages
split_page_table_lock
vmalloced-kernel-stacks
z3fold
zsmalloc
......@@ -47,8 +64,6 @@ TODOLIST:
* arch_pgtable_helpers
* free_page_reporting
* hugetlbfs_reserv
* page_migration
* slub
* transhuge
* unevictable-lru
* vmalloced-kernel-stacks
:Original: Documentation/vm/page_frag.rst
:Original: Documentation/vm/page_frags.rst
:翻译:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment