Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src This is a preview of the uvm_hotplug(9) api code.



details:   https://anonhg.NetBSD.org/src/rev/5aa7cd598033
branches:  trunk
changeset: 819844:5aa7cd598033
user:      cherry <cherry%NetBSD.org@localhost>
date:      Mon Dec 19 12:21:29 2016 +0000

description:
This is a preview of the uvm_hotplug(9) api code.
This commit does not actually introduce the UVM_HOTPLUG option.
However it does provide developers a way to review, test and try out
the API.

To do this, please go to tests/sys/uvm/ and build and run the tests
there. The tests also have a set of basic load tests, to get a measure
of the performance penalties due to enabling the UVM_HOTPLUG option.

In order to build the tests you need to have at least done the
following in $SRC/

cd $SRC; $NBMAKE do-distrib-dirs includes
cd $SRC/lib/csu; $NBMAKE all install || exit
cd $SRC/external/gpl3/gcc/lib/libgcc/libgcc_s; $NBMAKE all install || exit
cd $SRC/external/gpl3/gcc/lib/libgcc/libgcc; $NBMAKE all install || exit
cd $SRC/lib/libc; $NBMAKE includes all install || exit
cd $SRC/lib/libpthread; $NBMAKE all install || exit
cd $SRC/lib/libm; $NBMAKE all install || exit
cd $SRC/external/gpl3/gcc/lib/libstdc++-v3/; $NBMAKE all install || exit

Once the development environment has these userspace libraries, one
can simple build using $NBMAKE and finally test the kernel API using

atf-run|atf-report

diffstat:

 share/man/man9/uvm_hotplug.9       |   527 +++++++
 sys/uvm/uvm_physseg.c              |  1395 +++++++++++++++++++++
 sys/uvm/uvm_physseg.h              |   118 +
 tests/sys/uvm/Makefile             |    24 +
 tests/sys/uvm/t_uvm_physseg.c      |  2378 ++++++++++++++++++++++++++++++++++++
 tests/sys/uvm/t_uvm_physseg_load.c |   741 +++++++++++
 6 files changed, 5183 insertions(+), 0 deletions(-)

diffs (truncated from 5207 to 300 lines):

diff -r 5f727f5f9590 -r 5aa7cd598033 share/man/man9/uvm_hotplug.9
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man9/uvm_hotplug.9      Mon Dec 19 12:21:29 2016 +0000
@@ -0,0 +1,527 @@
+.\"    $NetBSD: uvm_hotplug.9,v 1.1 2016/12/19 12:21:29 cherry Exp $
+.\"
+.\" Copyright (c) 2016 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Cherry G Mathew and Santhosh N Raju.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"    notice, this list of conditions and the following disclaimer in the
+.\"    documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd November 20, 2016
+.Dt UVM_HOTPLUG 9
+.Os
+.Sh NAME
+.Nm uvm_physseg_init ,
+.Nm uvm_physseg_valid ,
+.Nm uvm_physseg_get_start ,
+.Nm uvm_physseg_get_end ,
+.Nm uvm_physseg_get_avail_start ,
+.Nm uvm_physseg_get_avail_end ,
+.Nm uvm_physseg_get_pg ,
+.Nm uvm_physseg_get_pmseg ,
+.Nm uvm_physseg_get_free_list ,
+.Nm uvm_physseg_get_start_hint ,
+.Nm uvm_physseg_set_start_hint ,
+.Nm uvm_physseg_get_next ,
+.Nm uvm_physseg_get_prev ,
+.Nm uvm_physseg_get_first ,
+.Nm uvm_physseg_get_last ,
+.Nm uvm_physseg_get_highest_frame ,
+.Nm uvm_physseg_find ,
+.Nm uvm_page_physload ,
+.Nm uvm_page_physunload ,
+.Nm uvm_page_physunload_force ,
+.Nm uvm_physseg_plug ,
+.Nm uvm_physseg_unplug ,
+.Nm uvm_physseg_set_avail_start ,
+.Nm uvm_physseg_set_avail_end
+.Nd memory hotplug manager
+.Sh SYNOPSIS
+.In uvm/uvm_physseg.h
+.Ft void
+.Fn uvm_physseg_init "void"
+.Ft uvm_physseg_t
+.Fn uvm_page_physload "paddr_t start" "paddr_t end" "paddr_t avail_start" \
+"paddr_t avail_end" "int free_list"
+.Ft bool
+.Fn uvm_page_physunload "uvm_physseg_t upm" "int free_list" \
+"paddr_t *paddrp"
+.Ft bool
+.Fn uvm_page_physunload_force "uvm_physseg_t upm" "int free_list" \
+"paddr_t *paddrp"
+.Ft bool
+.Fn uvm_physseg_plug "paddr_t pfn" "size_t npages" "uvm_physseg_t *upmp"
+.Ft bool
+.Fn uvm_physseg_unplug "paddr_t pfn" "size_t npages"
+.Sh DESCRIPTION
+These utility routines provide the ability to tell
+.Pq Xr uvm 9
+about system memory segments.
+When the kernel is compiled with
+.Cd 'options UVM_HOTPLUG'
+, memory segments are handled in a dynamic data structure
+.Pq Xr rbtree 3
+compared to a static array when not. This enables kernel code to add
+or remove information about memory segments at any point after boot -
+thus "hotplug".
+.Pp
+.Fn uvm_page_physload
+.Fn uvm_page_physunload
+and
+.Fn uvm_page_physunload_force
+are legacy interfaces which may be removed in the future. They must
+never be used after
+.Pq Xr uvm_init 9
+.Pp
+WARNING: This is an experimental feature and should not be used in production
+environments. Furthermore, attempting to "hotplug" without
+.Cd 'options UVM_HOTPLUG'
+after boot will almost certainly end in a
+.Pq Xr panic 9
+.Sh USAGE
+.Ss INITIALIZING HOTPLUG
+The function
+.Fn uvm_physseg_init
+initializes the hotplug subsystem. This is expected to happen exactly
+once, at boot time, and from MD code.
+.Ss PLUGGING IN MEMORY
+.Fn uvm_page_physload
+registers
+.Pq Xr uvm 9
+with a memory segment span, and on a specified
+.Fa free_list.
+It must be called at system boot time as part of setting up memory
+management.
+The arguments describe the start and end of the physical addresses of the
+segment, and the available start and end addresses of pages not already in use.
+If a system has memory banks of different speeds the slower memory should be
+given a higher
+.Fa free_list
+value.
+.Bl -tag -offset indent -width "avail_start"
+.It Fa start
+Starting page frame number of the physical memory segments.
+.It Fa end
+Ending page frame number of the physical memory segments.
+.It Fa avail_start
+Available starting page frame number of the physical memory segments.
+.It Fa avail_end
+Available ending page frame number of the physical memory segments.
+.It Fa free_list
+The free list type are defined in the Machine Dependent code.
+.El
+.Pp
+This function returns a valid
+.Dv uvm_physseg_t
+handle when a successful plug occurs, else it will return
+.Dv UVM_PHYSSEG_TYPE_INVALID
+when the plug fails.
+.Pp
+.Fn uvm_physseg_plug
+registers
+.Pq Xr uvm 9
+with a memory segment span.
+It can also be called to initiate a hotplug and register a newly
+"hotplugged" physical memory range into the VM. Unlike
+.Fn uvm_page_physload
+this function can, if
+.Cd 'options UVM_HOTPLUG'
+is enabled at compile time, be used after
+.Pq Xr uvm_init 9
+The arguments describe the start page frame, the number of pages to
+plug starting from the start page frame and an optional return variable, which
+points to a valid
+.Fa uvm_physseg_t
+handle when a successful plug occurs.
+.Bl -tag -offset indent -width "npages"
+.It Fa pfn
+Starting page frame number of the physical memory segment.
+.It Fa npages
+Total number of pages from the starting page frame number to plug in.
+.It Fa upmp
+If upmp is not
+.Fa NULL ,
+then on a successful plug, a valid pointer to the uvm_physseg_t handle
+for the segment which was plugged is returned.
+.El
+.Pp
+This function returns
+.Fa true
+when a successful plug occurs, 
+.Fa false
+otherwise.
+.Ss UNPLUGGING MEMORY
+The functions
+.Fn uvm_page_physunload
+,
+.Fn uvm_page_physunload_force
+and
+.Fn uvm_physseg_unplug
+make
+.Pq Xr uvm 9
+forget about previously registered memory segments or portions of
+such.
+.Pp
+.Fn uvm_page_physunload
+unloads pages from a segment (from the front or from the back)
+depending on its availability. When the last page is removed, the
+segment handle is invalidated and supporting metadata is freed.
+.Pp Note: This function can only be used during boot time.
+Pages, once unloaded, are unregistered from uvm and are therefore
+assumed to be managed by the code which called
+.Fn uvm_page_physunload 9
+(usually boot time MD code, for boottime memory "allocation").
+.Pp
+The arguments are:
+.Bl -tag -offset indent -width "free_list"
+.It Fa upm
+The handle identifying segment from which we are trying to unload memory.
+.It Fa free_list
+The free list type are defined in the Machine Dependent code.
+.It Fa paddrp
+The pointer to the physical address that was unloaded.
+.El
+.Pp
+If the unload was successful,
+.Fa true
+is returned,
+.Fa false
+otherwise.
+.Pp
+.Fn uvm_page_physunload_force
+unconditionally unloads pages from a segment.
+When the last page is removed, the segment handle
+is invalidated and supporting metadata is freed.
+.Pp Note: This function can only be used during boot time.
+Pages, once unloaded, are unregistered from uvm and are therefore
+assumed to be managed by the code which called
+.Fn uvm_page_physunload_force 9
+(usually boot time MD code, for boottime memory "allocation").
+.Pp
+The arguments are:
+.Bl -tag -offset indent -width "free_list"
+.It Fa upm
+The handle identifying segment from which we are trying to unload memory.
+.It Fa free_list
+The free list type are defined in the Machine Dependent code.
+.It Fa paddrp
+The pointer to the physical address that was unloaded.
+.El
+.Pp
+If the unload the successful
+.Fa true
+is returned,
+.Fa false
+otherwise.
+.Pp
+.Fn uvm_physseg_unplug
+can be called to unplug an existing physical memory segment. Unlike
+.Fn uvm_page_physunload
+and
+.Fn uvm_page_physunload_force
+, it can be called after
+.Pq Xr uvm_init 9
+, if
+.Cd 'options UVM_HOTPLUG'
+is enabled at compile time.
+.Fn uvm_hotplug 9
+makes no effort to manage the state of the underlying physical
+memory. It is upto the caller to ensure that it is not in use,
+either by
+.Pq Xr uvm 9
+, or by any other sub-system. Further, any hardware
+quiescing that may be required, is the responsibility of MD code.
+The arguments
+describe the start page frame and the number of pages to unplug.
+The arguments are:
+.Bl -tag -offset indent -width "npages"
+.It Fa pfn
+Starting page frame number of the physical memory segment.
+.It Fa npages
+Total number of pages from the starting page frame number to unplug.
+.El
+.Pp
+Returns
+.Fa true
+or
+.Fa false
+depending on success or failure respectively.
+.Sh UTILITY FUNCTIONS
+.Bl -ohang
+.It bool
+.Fn uvm_physseg_valid "uvm_physseg_t upm";
+.It paddr_t
+.Fn uvm_physseg_get_start "uvm_physseg_t upm";
+.It paddr_t
+.Fn uvm_physseg_get_end "uvm_physseg_t upm";
+.It paddr_t
+.Fn uvm_physseg_get_avail_start "uvm_physseg_t upm";
+.It paddr_t
+.Fn uvm_physseg_get_avail_end "uvm_physseg_t upm";
+.It struct vm_page *
+.Fn uvm_physseg_get_pg "uvm_physseg_t upm" "paddr_t index";
+.It struct pmap_physseg *
+.Fn uvm_physseg_get_pmesg "uvm_physseg_t upm";
+.It int
+.Fn uvm_physseg_get_free_list "uvm_physseg_t upm";
+.It u_int
+.Fn uvm_physseg_get_start_hint "uvm_physseg_t upm";
+.It bool
+.Fn uvm_physseg_set_start_hint "uvm_physseg_t upm" "u_int start_hint";
+.It uvm_physseg_t
+.Fn uvm_physseg_get_next "uvm_physseg_t upm";
+.It uvm_physseg_t
+.Fn uvm_physseg_get_prev "uvm_physseg_t upm";
+.It uvm_physseg_t
+.Fn uvm_physseg_get_first "void";



Home | Main Index | Thread Index | Old Index