[PATCH 6/8] e820.py - how much memory ?

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

 



$Id: patch6.in /main/7 2009/07/10 16:36:05 alfords Exp $
Copyright 2009 Automatic Data Processing, Inc.

See the README file in the first patch of this series for
important details.

e820.py is a Python script.  It defines the e820Info class.  The
e820Info class reads the BIOS 15h/e820 memory map.  We found that
map to be a somewhat more reliable indicator of how much memory
was actually on the system than /proc/meminfo.  That map can can
be found in /tmp/syslog while ramdisk Linux runs, or in
/var/log/dmesg when regular Linux runs.  The e820Info class can
provide a sum of the memory reported found in the e820 map.  The
e820Info class recognizes the e820 map formats produced by the
2.4.* and 2.6* kernels with which we have tried it.

e820.py has not changed since 2002, since I distributed it the
first time.  For completeness, I'm sending it out again.  The
"COPYING" file it refers to is, of course, the file that holds
the text of the GNU General Public License Version 2.

--Seth Alford
ADP Dealer Services
seth_alford@xxxxxxx

----e820.py follows----
#! /usr/bin/python
# $Id: e820.py /main/8 2002/07/10 19:53:47 setha Exp $
#
# Reads the e820 map near the start of the input file.
#
# Copyright (c) 2001-2002 Automatic Data Processing Inc.  The distribution
# terms are as noted in the file COPYING.

import sys
import re
import string

class e820Info:

	# Get information about memory from the memory map printed
	# by the 15h/e820 BIOS call, which is presumed to be in the
	# file supplied in parameter file.  That file is either one or
	# another form of syslog output; or /proc/e820info in later 2.4
	# series kernels with e820 proc info enabled in .config.
	#
	# By default, this class assumes /proc/e820info.  Pass a file
	# parameter to look in one or more of the syslog output files.
	def __init__(self, file="/proc/e820info"):

		try:
			f=open(file, "r")
		except:
			print "Could not open", file
			sys.exit(1)

		e820map=0
		accum=0

		# This class recognizes 4 forms of the e820 map.  Forms
		# 1-3 are found in one of the syslog output files.
		# Form 4 is found only in /proc/e820info.
		# Form 1:
		#  BIOS-e820: start - end (usable)
		# Form 2:
		# <4> BIOS-e820: size @ start (usable)
		# Form 3:
		# <4> BIOS-e820: start - end (usable)
		# Form 4, only in /proc/e820info:
		# size @ start (usable)
		#
		# I have only seen form 2 in the ramdisk environment
		# with the 2.4.2 kernel.  Form 2 is therefore older.
		# I believe that syslog in the ramdisk environment
		# prepends the "<4>".  We first saw form 3 in Martin's
		# PC with the 2.4.10 kernel.

		if file == "/proc/e820info":
			e820map=4

		while 1:
			l=f.readline()
			if not l: break
			fields=string.split(l)

			if e820map==1 and fields[0] != "BIOS-e820:":
		 		# Done reading the map
				break

			if (e820map==2 or e820map==3) and fields[1] != "BIOS-e820:":
		 		# Done reading the map
				break

			if fields[0] == "BIOS-e820:" and e820map==0:
				e820map=1

			if fields[0] == "<4>" and fields[1] == "BIOS-e820:" and e820map==0:
				if fields[3] == "@":
					e820map=2
				elif fields[3] == "-":
					e820map=3
				else:
					print "Unknown e820 log file format (form 2 or 3,) giving up"
					sys.exit(1)

			if not e820map:
				continue

			if e820map == 1 or e820map == 3:
				# Convert the type 3 into a type 1
				if e820map == 3:
					fields=fields[1:]
				# Form 1 e820 map sanity check:
				if fields[2] != "-":
					print "Unknown e820 log file format (form 1 or 3,) giving up"
					sys.exit(1)
				start=string.atol(fields[1],16)
				end=string.atol(fields[3],16)
				diff = end - start
				if fields[4] == "(usable)" or fields[4] == "(ACPI data)":
					accum = accum + diff

			if e820map == 2 or e820map == 4:
				# Convert the type 2 information into a type 4
				if e820map == 2:
					fields=fields[2:]
				# Treat fields as a form 4 e820 map
				# Sanity check:
				if fields[1] != "@":
					print "Unknown log file format (form 2 or 4,) giving up"
					sys.exit(1)
				diff = string.atol(fields[0],16)
				if fields[3] == "(usable)" or fields[3] == "(ACPI data)":
					accum = accum + diff

		# If we get here, and e820map is still 0, then we could not find
		# an e820 map and so it is time to give up.
		if not e820map:
			print "Could not find e820 map, giving up"
			sys.exit(1)

		megabyte = 1024.0*1024.0
		self.memtotal = int(round(accum/megabyte))

if __name__ == '__main__':

	if len(sys.argv) != 2:
		print "Usage: %s log_file" % sys.argv[0] 
		sys.exit(1)
		#NOTREACHED

	e820info = e820Info(file=sys.argv[1])

	print e820info.memtotal
	sys.exit(0)


This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux