/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* i86pc Memory Scrubbing
*
* On detection of a correctable memory ECC error, the i86pc hardware
* returns the corrected data to the requester and may re-write it
* to memory (DRAM or NVRAM). Machines which do not re-write this to
* memory should add an NMI handler to correct and rewrite.
*
* Scrubbing thus reduces the likelyhood that multiple transient errors
* will occur in the same memory word, making uncorrectable errors due
* to transients less likely.
*
* Thus is born the desire that every memory location be periodically
* accessed.
*
* This file implements a memory scrubbing thread. This scrubber
* guarantees that all of physical memory is accessed periodically
* (memscrub_period_sec -- 12 hours).
*
* It attempts to do this as unobtrusively as possible. The thread
* schedules itself to wake up at an interval such that if it reads
* memscrub_span_pages (4MB) on each wakeup, it will read all of physical
* memory in in memscrub_period_sec (12 hours).
*
* The scrubber uses the REP LODS so it reads 4MB in 0.15 secs (on P5-200).
* When it completes a span, if all the CPUs are idle, it reads another span.
* Typically it soaks up idle time this way to reach its deadline early
* -- and sleeps until the next period begins.
*
* Maximal Cost Estimate: 8GB @ xxMB/s = xxx seconds spent in 640 wakeups
* that run for 0.15 seconds at intervals of 67 seconds.
*
* In practice, the scrubber finds enough idle time to finish in a few
* minutes, and sleeps until its 12 hour deadline.
*
* The scrubber maintains a private copy of the phys_install memory list
* to keep track of what memory should be scrubbed.
*
*
* memscrub_span_pages = MEMSCRUB_DFL_SPAN_PAGES (4MB)
* memscrub_period_sec = MEMSCRUB_DFL_PERIOD_SEC (12 hours)
* memscrub_thread_pri = MEMSCRUB_DFL_THREAD_PRI (0)
* memscrub_delay_start_sec = (10 seconds)
* disable_memscrub = (0)
*
* the scrubber will exit (or never be started) if it finds the variable
* "disable_memscrub" set.
*
* MEMSCRUB_DFL_SPAN_PAGES is based on the guess that 0.15 sec
* is a "good" amount of minimum time for the thread to run at a time.
*
* MEMSCRUB_DFL_PERIOD_SEC (12 hours) is nearly a total guess --
* twice the frequency the hardware folk estimated would be necessary.
*
* MEMSCRUB_DFL_THREAD_PRI (0) is based on the assumption that nearly
* any other use of the system should be higher priority than scrubbing.
*/
#include <vm/seg_kmem.h>
/*
* Global Data:
*/
/*
* scan all of physical memory at least once every MEMSCRUB_PERIOD_SEC
*/
/*
* start only if at least MEMSCRUB_MIN_PAGES in system
*/
/*
* scan at least MEMSCRUB_DFL_SPAN_PAGES each iteration
*/
/*
* almost anything is higher priority than scrubbing
*/
#define MEMSCRUB_DFL_THREAD_PRI 0
/*
*/
/*
* Static Routines
*/
static void memscrubber(void);
static int system_is_idle(void);
/*
* Static Data
*/
/*
* memscrub_lock protects memscrub_memlist
*/
/*
* create memscrub_memlist from phys_install list
* initialize locks, set memscrub_phys_pages.
*/
void
{
if (physmem < memscrub_min_pages)
return;
if (!kpm_enable) {
}
/*
* copy phys_install to memscrub_memlist
*/
"Software memory scrubber failed to initialize\n");
return;
}
}
/*
* create memscrubber thread
*/
}
/*
* Function to cause the software memscrubber to exit quietly if the
* platform support has located a hardware scrubber and enabled it.
*/
void
memscrub_disable(void)
{
}
#ifdef MEMSCRUB_DEBUG
static void
{
}
}
#endif /* MEMSCRUB_DEBUG */
/* ARGSUSED */
static void
memscrub_wakeup(void *c)
{
/*
* grab mutex to guarantee that our wakeup call
* arrives after we go to sleep -- so we can't sleep forever.
*/
}
/*
* this calculation doesn't account for the time that the actual scan
* consumes -- so we'd fall slightly behind schedule with this
* interval_sec. but the idle loop optimization below usually makes us
* come in way ahead of schedule.
*/
static int
{
return (memscrub_period_sec);
else
return (memscrub_period_sec/
}
static void
{
/*
* notify CPR of our existence
*/
if (memscrub_memlist == NULL) {
goto memscrub_exit;
}
for (;;) {
break;
/*
* did we just reach the end of memory?
*/
if (reached_end) {
/*
* past deadline, start right away
*/
interval_sec = 0;
} else {
/*
* we finished ahead of schedule.
* wait till previous dealine before re-start.
*/
}
} else {
}
/*
* it is safe from our standpoint for CPR to
* suspend the system
*/
/*
* hit the snooze bar
*/
/*
* go to sleep
*/
/* we need to goto work */
do {
break;
/*
* Make sure we don't try to scan beyond the end of
* the current memlist. If we would, then resize
* our scan target for this iteration, and prepare
* to read the next memlist entry on the next
* iteration.
*/
reached_end = 0;
reached_end = 1;
}
} else {
}
while (pages--) {
/*
* Without segkpm, the memscrubber cannot
* be allowed to migrate across CPUs, as
* the CPU-specific mapping of
* memscrub_window would be incorrect.
* With segkpm, switching CPUs is legal, but
* inefficient. We don't use
* kpreempt_disable as it might hold a
* higher priority thread (eg, RT) too long
* off CPU.
*/
if (kpm_enable)
else
address += MMU_PAGESIZE;
}
} while (!reached_end && system_is_idle());
}
if (!disable_memscrub_quietly)
/*
* We are about to bail, but don't have the memscrub_lock,
* and it is needed for CALLB_CPR_EXIT.
*/
thread_exit();
}
/*
* return 1 if we're MP and all the other CPUs are idle
*/
static int
{
int cpu_id;
int found = 0;
if (1 == ncpus_online)
return (0);
continue;
found++;
continue;
return (0);
}
break;
}
return (1);
}
/*
* add a span to the memscrub list
*/
static int
{
int retval = 0;
#ifdef MEMSCRUB_DEBUG
#endif /* MEMSCRUB_DEBUG */
/*
* Scan through the list to find the proper place to install it.
*/
while (next) {
/*
* If this span overlaps with an existing span, then
* something has gone horribly wrong with the phys_install
* list. In fact, I'm surprised we made it this far.
*/
panic("memscrub found overlapping memory ranges "
"(0x%p-0x%p) and (0x%p-0x%p)",
/*
* New span can be appended to an existing one.
*/
goto add_done;
}
/*
* New span can be prepended to an existing one.
*/
goto add_done;
}
/*
* If the next span has a higher start address than the new
* one, then we have found the right spot for our
* insertion.
*/
break;
}
/*
* allocate a new struct memlist
*/
retval = -1;
goto add_done;
}
if (prev)
else
if (next)
if (retval != -1)
#ifdef MEMSCRUB_DEBUG
#endif /* MEMSCRUB_DEBUG */
return (retval);
}