···457457458458Note, a technical ChangeLog aimed at kernel hackers is in fs/ntfs/ChangeLog.459459460460+2.1.30:461461+ - Fix writev() (it kept writing the first segment over and over again462462+ instead of moving onto subsequent segments).4604632.1.29:461464 - Fix a deadlock when mounting read-write.4624652.1.28:
+3-3
MAINTAINERS
···43834383F: drivers/scsi/nsp32*4384438443854385NTFS FILESYSTEM43864386-M: Anton Altaparmakov <aia21@cantab.net>43864386+M: Anton Altaparmakov <anton@tuxera.com>43874387L: linux-ntfs-dev@lists.sourceforge.net43884388-W: http://www.linux-ntfs.org/43884388+W: http://www.tuxera.com/43894389T: git git://git.kernel.org/pub/scm/linux/kernel/git/aia21/ntfs-2.6.git43904390-S: Maintained43904390+S: Supported43914391F: Documentation/filesystems/ntfs.txt43924392F: fs/ntfs/43934393
+18
arch/sh/boards/Kconfig
···33config SOLUTION_ENGINE44 bool5566+config SH_ALPHA_BOARD77+ bool88+69config SH_SOLUTION_ENGINE710 bool "SolutionEngine"811 select SOLUTION_ENGINE···322319 It has an Ethernet interface (SMC9118), direct connected323320 Compact Flash socket, two serial ports and PC-104 bus.324321 More information at <http://sh2000.sh-linux.org>.322322+323323+config SH_APSH4A3A324324+ bool "AP-SH4A-3A"325325+ select SH_ALPHA_BOARD326326+ depends on CPU_SUBTYPE_SH7785327327+ help328328+ Select AP-SH4A-3A if configuring for an ALPHAPROJECT AP-SH4A-3A.329329+330330+config SH_APSH4AD0A331331+ bool "AP-SH4AD-0A"332332+ select SH_ALPHA_BOARD333333+ select SYS_SUPPORTS_PCI334334+ depends on CPU_SUBTYPE_SH7786335335+ help336336+ Select AP-SH4AD-0A if configuring for an ALPHAPROJECT AP-SH4AD-0A.325337326338endmenu327339
···11+/*22+ * ALPHAPROJECT AP-SH4A-3A Support.33+ *44+ * Copyright (C) 2010 ALPHAPROJECT Co.,Ltd.55+ * Copyright (C) 2008 Yoshihiro Shimoda66+ * Copyright (C) 2009 Paul Mundt77+ *88+ * This file is subject to the terms and conditions of the GNU General Public99+ * License. See the file "COPYING" in the main directory of this archive1010+ * for more details.1111+ */1212+#include <linux/init.h>1313+#include <linux/platform_device.h>1414+#include <linux/io.h>1515+#include <linux/mtd/physmap.h>1616+#include <linux/smsc911x.h>1717+#include <linux/irq.h>1818+#include <linux/clk.h>1919+#include <asm/machvec.h>2020+#include <asm/sizes.h>2121+#include <asm/clock.h>2222+2323+static struct mtd_partition nor_flash_partitions[] = {2424+ {2525+ .name = "loader",2626+ .offset = 0x00000000,2727+ .size = 512 * 1024,2828+ },2929+ {3030+ .name = "bootenv",3131+ .offset = MTDPART_OFS_APPEND,3232+ .size = 512 * 1024,3333+ },3434+ {3535+ .name = "kernel",3636+ .offset = MTDPART_OFS_APPEND,3737+ .size = 4 * 1024 * 1024,3838+ },3939+ {4040+ .name = "data",4141+ .offset = MTDPART_OFS_APPEND,4242+ .size = MTDPART_SIZ_FULL,4343+ },4444+};4545+4646+static struct physmap_flash_data nor_flash_data = {4747+ .width = 4,4848+ .parts = nor_flash_partitions,4949+ .nr_parts = ARRAY_SIZE(nor_flash_partitions),5050+};5151+5252+static struct resource nor_flash_resources[] = {5353+ [0] = {5454+ .start = 0x00000000,5555+ .end = 0x01000000 - 1,5656+ .flags = IORESOURCE_MEM,5757+ }5858+};5959+6060+static struct platform_device nor_flash_device = {6161+ .name = "physmap-flash",6262+ .dev = {6363+ .platform_data = &nor_flash_data,6464+ },6565+ .num_resources = ARRAY_SIZE(nor_flash_resources),6666+ .resource = nor_flash_resources,6767+};6868+6969+static struct resource smsc911x_resources[] = {7070+ [0] = {7171+ .name = "smsc911x-memory",7272+ .start = 0xA4000000,7373+ .end = 0xA4000000 + SZ_256 - 1,7474+ .flags = IORESOURCE_MEM,7575+ },7676+ [1] = {7777+ .name = "smsc911x-irq",7878+ .start = evt2irq(0x200),7979+ .end = evt2irq(0x200),8080+ .flags = IORESOURCE_IRQ,8181+ },8282+};8383+8484+static struct smsc911x_platform_config smsc911x_config = {8585+ .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,8686+ .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,8787+ .flags = SMSC911X_USE_16BIT,8888+ .phy_interface = PHY_INTERFACE_MODE_MII,8989+};9090+9191+static struct platform_device smsc911x_device = {9292+ .name = "smsc911x",9393+ .id = -1,9494+ .num_resources = ARRAY_SIZE(smsc911x_resources),9595+ .resource = smsc911x_resources,9696+ .dev = {9797+ .platform_data = &smsc911x_config,9898+ },9999+};100100+101101+static struct platform_device *apsh4a3a_devices[] __initdata = {102102+ &nor_flash_device,103103+ &smsc911x_device,104104+};105105+106106+static int __init apsh4a3a_devices_setup(void)107107+{108108+ return platform_add_devices(apsh4a3a_devices,109109+ ARRAY_SIZE(apsh4a3a_devices));110110+}111111+device_initcall(apsh4a3a_devices_setup);112112+113113+static int apsh4a3a_clk_init(void)114114+{115115+ struct clk *clk;116116+ int ret;117117+118118+ clk = clk_get(NULL, "extal");119119+ if (!clk || IS_ERR(clk))120120+ return PTR_ERR(clk);121121+ ret = clk_set_rate(clk, 33333000);122122+ clk_put(clk);123123+124124+ return ret;125125+}126126+127127+/* Initialize the board */128128+static void __init apsh4a3a_setup(char **cmdline_p)129129+{130130+ printk(KERN_INFO "Alpha Project AP-SH4A-3A support:\n");131131+}132132+133133+static void __init apsh4a3a_init_irq(void)134134+{135135+ plat_irq_setup_pins(IRQ_MODE_IRQ7654);136136+}137137+138138+/* Return the board specific boot mode pin configuration */139139+static int apsh4a3a_mode_pins(void)140140+{141141+ int value = 0;142142+143143+ /* These are the factory default settings of SW1 and SW2.144144+ * If you change these dip switches then you will need to145145+ * adjust the values below as well.146146+ */147147+ value &= ~MODE_PIN0; /* Clock Mode 16 */148148+ value &= ~MODE_PIN1;149149+ value &= ~MODE_PIN2;150150+ value &= ~MODE_PIN3;151151+ value |= MODE_PIN4;152152+ value &= ~MODE_PIN5; /* 16-bit Area0 bus width */153153+ value |= MODE_PIN6; /* Area 0 SRAM interface */154154+ value |= MODE_PIN7;155155+ value |= MODE_PIN8; /* Little Endian */156156+ value |= MODE_PIN9; /* Master Mode */157157+ value |= MODE_PIN10; /* Crystal resonator */158158+ value |= MODE_PIN11; /* Display Unit */159159+ value |= MODE_PIN12;160160+ value &= ~MODE_PIN13; /* 29-bit address mode */161161+ value |= MODE_PIN14; /* No PLL step-up */162162+163163+ return value;164164+}165165+166166+/*167167+ * The Machine Vector168168+ */169169+static struct sh_machine_vector mv_apsh4a3a __initmv = {170170+ .mv_name = "AP-SH4A-3A",171171+ .mv_setup = apsh4a3a_setup,172172+ .mv_clk_init = apsh4a3a_clk_init,173173+ .mv_init_irq = apsh4a3a_init_irq,174174+ .mv_mode_pins = apsh4a3a_mode_pins,175175+};
+125
arch/sh/boards/board-apsh4ad0a.c
···11+/*22+ * ALPHAPROJECT AP-SH4AD-0A Support.33+ *44+ * Copyright (C) 2010 ALPHAPROJECT Co.,Ltd.55+ * Copyright (C) 2010 Matt Fleming66+ * Copyright (C) 2010 Paul Mundt77+ *88+ * This file is subject to the terms and conditions of the GNU General Public99+ * License. See the file "COPYING" in the main directory of this archive1010+ * for more details.1111+ */1212+#include <linux/init.h>1313+#include <linux/platform_device.h>1414+#include <linux/io.h>1515+#include <linux/smsc911x.h>1616+#include <linux/irq.h>1717+#include <linux/clk.h>1818+#include <asm/machvec.h>1919+#include <asm/sizes.h>2020+2121+static struct resource smsc911x_resources[] = {2222+ [0] = {2323+ .name = "smsc911x-memory",2424+ .start = 0xA4000000,2525+ .end = 0xA4000000 + SZ_256 - 1,2626+ .flags = IORESOURCE_MEM,2727+ },2828+ [1] = {2929+ .name = "smsc911x-irq",3030+ .start = evt2irq(0x200),3131+ .end = evt2irq(0x200),3232+ .flags = IORESOURCE_IRQ,3333+ },3434+};3535+3636+static struct smsc911x_platform_config smsc911x_config = {3737+ .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,3838+ .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,3939+ .flags = SMSC911X_USE_16BIT,4040+ .phy_interface = PHY_INTERFACE_MODE_MII,4141+};4242+4343+static struct platform_device smsc911x_device = {4444+ .name = "smsc911x",4545+ .id = -1,4646+ .num_resources = ARRAY_SIZE(smsc911x_resources),4747+ .resource = smsc911x_resources,4848+ .dev = {4949+ .platform_data = &smsc911x_config,5050+ },5151+};5252+5353+static struct platform_device *apsh4ad0a_devices[] __initdata = {5454+ &smsc911x_device,5555+};5656+5757+static int __init apsh4ad0a_devices_setup(void)5858+{5959+ return platform_add_devices(apsh4ad0a_devices,6060+ ARRAY_SIZE(apsh4ad0a_devices));6161+}6262+device_initcall(apsh4ad0a_devices_setup);6363+6464+static int apsh4ad0a_mode_pins(void)6565+{6666+ int value = 0;6767+6868+ /* These are the factory default settings of SW1 and SW2.6969+ * If you change these dip switches then you will need to7070+ * adjust the values below as well.7171+ */7272+ value |= MODE_PIN0; /* Clock Mode 3 */7373+ value |= MODE_PIN1;7474+ value &= ~MODE_PIN2;7575+ value &= ~MODE_PIN3;7676+ value &= ~MODE_PIN4; /* 16-bit Area0 bus width */7777+ value |= MODE_PIN5;7878+ value |= MODE_PIN6;7979+ value |= MODE_PIN7; /* Normal mode */8080+ value |= MODE_PIN8; /* Little Endian */8181+ value |= MODE_PIN9; /* Crystal resonator */8282+ value &= ~MODE_PIN10; /* 29-bit address mode */8383+ value &= ~MODE_PIN11; /* PCI-E Root port */8484+ value &= ~MODE_PIN12; /* 4 lane + 1 lane */8585+ value |= MODE_PIN13; /* AUD Enable */8686+ value &= ~MODE_PIN14; /* Normal Operation */8787+8888+ return value;8989+}9090+9191+static int apsh4ad0a_clk_init(void)9292+{9393+ struct clk *clk;9494+ int ret;9595+9696+ clk = clk_get(NULL, "extal");9797+ if (!clk || IS_ERR(clk))9898+ return PTR_ERR(clk);9999+ ret = clk_set_rate(clk, 33333000);100100+ clk_put(clk);101101+102102+ return ret;103103+}104104+105105+/* Initialize the board */106106+static void __init apsh4ad0a_setup(char **cmdline_p)107107+{108108+ pr_info("Alpha Project AP-SH4AD-0A support:\n");109109+}110110+111111+static void __init apsh4ad0a_init_irq(void)112112+{113113+ plat_irq_setup_pins(IRQ_MODE_IRQ3210);114114+}115115+116116+/*117117+ * The Machine Vector118118+ */119119+static struct sh_machine_vector mv_apsh4ad0a __initmv = {120120+ .mv_name = "AP-SH4AD-0A",121121+ .mv_setup = apsh4ad0a_setup,122122+ .mv_mode_pins = apsh4ad0a_mode_pins,123123+ .mv_clk_init = apsh4ad0a_clk_init,124124+ .mv_init_irq = apsh4ad0a_init_irq,125125+};
+102
arch/sh/configs/apsh4a3a_defconfig
···11+CONFIG_EXPERIMENTAL=y22+CONFIG_SYSVIPC=y33+CONFIG_BSD_PROCESS_ACCT=y44+CONFIG_IKCONFIG=y55+CONFIG_IKCONFIG_PROC=y66+CONFIG_LOG_BUF_SHIFT=1477+CONFIG_SYSFS_DEPRECATED=y88+CONFIG_SYSFS_DEPRECATED_V2=y99+CONFIG_BLK_DEV_INITRD=y1010+CONFIG_SLAB=y1111+CONFIG_PROFILING=y1212+CONFIG_MODULES=y1313+CONFIG_MODULE_UNLOAD=y1414+# CONFIG_BLK_DEV_BSG is not set1515+CONFIG_CPU_SUBTYPE_SH7785=y1616+CONFIG_MEMORY_START=0x0C0000001717+CONFIG_FLATMEM_MANUAL=y1818+CONFIG_SH_STORE_QUEUES=y1919+CONFIG_SH_APSH4A3A=y2020+CONFIG_HIGH_RES_TIMERS=y2121+CONFIG_KEXEC=y2222+CONFIG_PREEMPT=y2323+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set2424+CONFIG_NET=y2525+CONFIG_PACKET=y2626+CONFIG_UNIX=y2727+CONFIG_INET=y2828+CONFIG_IP_ADVANCED_ROUTER=y2929+CONFIG_IP_PNP=y3030+CONFIG_IP_PNP_DHCP=y3131+# CONFIG_INET_LRO is not set3232+# CONFIG_IPV6 is not set3333+# CONFIG_WIRELESS is not set3434+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"3535+# CONFIG_FW_LOADER is not set3636+CONFIG_MTD=y3737+CONFIG_MTD_CONCAT=y3838+CONFIG_MTD_PARTITIONS=y3939+CONFIG_MTD_CHAR=y4040+CONFIG_MTD_BLOCK=y4141+CONFIG_MTD_CFI=y4242+CONFIG_MTD_CFI_AMDSTD=y4343+CONFIG_MTD_PHYSMAP=y4444+CONFIG_BLK_DEV_RAM=y4545+CONFIG_BLK_DEV_RAM_SIZE=163844646+CONFIG_NETDEVICES=y4747+CONFIG_NET_ETHERNET=y4848+CONFIG_SMSC911X=y4949+# CONFIG_NETDEV_1000 is not set5050+# CONFIG_NETDEV_10000 is not set5151+# CONFIG_WLAN is not set5252+# CONFIG_INPUT_MOUSEDEV is not set5353+# CONFIG_INPUT_KEYBOARD is not set5454+# CONFIG_INPUT_MOUSE is not set5555+# CONFIG_SERIO is not set5656+CONFIG_VT_HW_CONSOLE_BINDING=y5757+CONFIG_SERIAL_SH_SCI=y5858+CONFIG_SERIAL_SH_SCI_NR_UARTS=65959+CONFIG_SERIAL_SH_SCI_CONSOLE=y6060+CONFIG_HW_RANDOM=y6161+# CONFIG_HWMON is not set6262+CONFIG_FB=y6363+CONFIG_FB_SH7785FB=y6464+CONFIG_FRAMEBUFFER_CONSOLE=y6565+CONFIG_FONTS=y6666+CONFIG_FONT_8x8=y6767+CONFIG_FONT_8x16=y6868+CONFIG_LOGO=y6969+# CONFIG_HID_SUPPORT is not set7070+# CONFIG_USB_SUPPORT is not set7171+CONFIG_EXT2_FS=y7272+CONFIG_EXT3_FS=y7373+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set7474+CONFIG_MSDOS_FS=y7575+CONFIG_VFAT_FS=y7676+CONFIG_NTFS_FS=y7777+CONFIG_NTFS_RW=y7878+CONFIG_PROC_KCORE=y7979+CONFIG_TMPFS=y8080+CONFIG_JFFS2_FS=y8181+CONFIG_CRAMFS=y8282+CONFIG_NFS_FS=y8383+CONFIG_NFS_V3=y8484+CONFIG_NFS_V4=y8585+CONFIG_CIFS=y8686+CONFIG_NLS_DEFAULT="utf8"8787+CONFIG_NLS_CODEPAGE_437=y8888+CONFIG_NLS_CODEPAGE_932=y8989+CONFIG_NLS_ASCII=y9090+CONFIG_NLS_ISO8859_1=y9191+CONFIG_NLS_UTF8=y9292+# CONFIG_ENABLE_WARN_DEPRECATED is not set9393+# CONFIG_ENABLE_MUST_CHECK is not set9494+CONFIG_DEBUG_FS=y9595+CONFIG_DEBUG_KERNEL=y9696+# CONFIG_DEBUG_PREEMPT is not set9797+# CONFIG_DEBUG_BUGVERBOSE is not set9898+CONFIG_DEBUG_INFO=y9999+# CONFIG_RCU_CPU_STALL_DETECTOR is not set100100+# CONFIG_FTRACE is not set101101+# CONFIG_CRYPTO_ANSI_CPRNG is not set102102+# CONFIG_CRYPTO_HW is not set
+133
arch/sh/configs/apsh4ad0a_defconfig
···11+CONFIG_EXPERIMENTAL=y22+CONFIG_SYSVIPC=y33+CONFIG_POSIX_MQUEUE=y44+CONFIG_BSD_PROCESS_ACCT=y55+CONFIG_RCU_TRACE=y66+CONFIG_IKCONFIG=y77+CONFIG_IKCONFIG_PROC=y88+CONFIG_LOG_BUF_SHIFT=1499+CONFIG_CGROUPS=y1010+CONFIG_CGROUP_NS=y1111+CONFIG_CGROUP_FREEZER=y1212+CONFIG_CGROUP_DEVICE=y1313+CONFIG_CGROUP_CPUACCT=y1414+CONFIG_RESOURCE_COUNTERS=y1515+CONFIG_CGROUP_MEM_RES_CTLR=y1616+CONFIG_BLK_CGROUP=y1717+CONFIG_NAMESPACES=y1818+CONFIG_BLK_DEV_INITRD=y1919+CONFIG_KALLSYMS_ALL=y2020+# CONFIG_COMPAT_BRK is not set2121+CONFIG_SLAB=y2222+CONFIG_PROFILING=y2323+CONFIG_MODULES=y2424+CONFIG_MODULE_UNLOAD=y2525+# CONFIG_LBDAF is not set2626+# CONFIG_BLK_DEV_BSG is not set2727+CONFIG_CFQ_GROUP_IOSCHED=y2828+CONFIG_CPU_SUBTYPE_SH7786=y2929+CONFIG_MEMORY_SIZE=0x100000003030+CONFIG_HUGETLB_PAGE_SIZE_1MB=y3131+CONFIG_MEMORY_HOTPLUG=y3232+CONFIG_MEMORY_HOTREMOVE=y3333+CONFIG_KSM=y3434+CONFIG_SH_STORE_QUEUES=y3535+CONFIG_SH_APSH4AD0A=y3636+CONFIG_NO_HZ=y3737+CONFIG_HIGH_RES_TIMERS=y3838+CONFIG_CPU_FREQ=y3939+CONFIG_CPU_FREQ_GOV_POWERSAVE=m4040+CONFIG_CPU_FREQ_GOV_USERSPACE=m4141+CONFIG_CPU_FREQ_GOV_ONDEMAND=m4242+CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m4343+CONFIG_SH_CPU_FREQ=y4444+CONFIG_KEXEC=y4545+CONFIG_SECCOMP=y4646+CONFIG_PREEMPT=y4747+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set4848+CONFIG_BINFMT_MISC=y4949+CONFIG_PM=y5050+CONFIG_PM_DEBUG=y5151+CONFIG_PM_VERBOSE=y5252+CONFIG_PM_RUNTIME=y5353+CONFIG_CPU_IDLE=y5454+CONFIG_NET=y5555+CONFIG_PACKET=y5656+CONFIG_UNIX=y5757+CONFIG_NET_KEY=y5858+CONFIG_INET=y5959+# CONFIG_INET_LRO is not set6060+# CONFIG_IPV6 is not set6161+# CONFIG_WIRELESS is not set6262+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"6363+# CONFIG_FW_LOADER is not set6464+CONFIG_MTD=y6565+CONFIG_MTD_CFI=y6666+CONFIG_BLK_DEV_RAM=y6767+CONFIG_BLK_DEV_RAM_SIZE=163846868+CONFIG_SCSI=y6969+CONFIG_BLK_DEV_SD=y7070+CONFIG_SCSI_MULTI_LUN=y7171+# CONFIG_SCSI_LOWLEVEL is not set7272+CONFIG_NETDEVICES=y7373+CONFIG_MDIO_BITBANG=y7474+CONFIG_NET_ETHERNET=y7575+CONFIG_SMSC911X=y7676+# CONFIG_NETDEV_1000 is not set7777+# CONFIG_NETDEV_10000 is not set7878+# CONFIG_WLAN is not set7979+CONFIG_INPUT_EVDEV=y8080+# CONFIG_INPUT_KEYBOARD is not set8181+# CONFIG_INPUT_MOUSE is not set8282+# CONFIG_SERIO is not set8383+CONFIG_SERIAL_SH_SCI=y8484+CONFIG_SERIAL_SH_SCI_NR_UARTS=68585+CONFIG_SERIAL_SH_SCI_CONSOLE=y8686+# CONFIG_LEGACY_PTYS is not set8787+# CONFIG_HW_RANDOM is not set8888+# CONFIG_HWMON is not set8989+CONFIG_VIDEO_OUTPUT_CONTROL=y9090+CONFIG_FB=y9191+CONFIG_FB_SH7785FB=y9292+CONFIG_FRAMEBUFFER_CONSOLE=y9393+CONFIG_FONTS=y9494+CONFIG_FONT_8x8=y9595+CONFIG_FONT_8x16=y9696+CONFIG_LOGO=y9797+CONFIG_USB=y9898+CONFIG_USB_DEBUG=y9999+CONFIG_USB_MON=y100100+CONFIG_USB_OHCI_HCD=y101101+CONFIG_USB_STORAGE=y102102+CONFIG_EXT2_FS=y103103+CONFIG_EXT3_FS=y104104+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set105105+CONFIG_MSDOS_FS=y106106+CONFIG_VFAT_FS=y107107+CONFIG_NTFS_FS=y108108+CONFIG_NTFS_RW=y109109+CONFIG_PROC_KCORE=y110110+CONFIG_TMPFS=y111111+CONFIG_HUGETLBFS=y112112+CONFIG_JFFS2_FS=y113113+CONFIG_CRAMFS=y114114+CONFIG_NFS_FS=y115115+CONFIG_NFS_V3=y116116+CONFIG_NFS_V4=y117117+CONFIG_CIFS=y118118+CONFIG_NLS_DEFAULT="utf8"119119+CONFIG_NLS_CODEPAGE_437=y120120+CONFIG_NLS_CODEPAGE_932=y121121+CONFIG_NLS_ASCII=y122122+CONFIG_NLS_ISO8859_1=y123123+CONFIG_NLS_UTF8=y124124+# CONFIG_ENABLE_MUST_CHECK is not set125125+CONFIG_MAGIC_SYSRQ=y126126+CONFIG_DEBUG_KERNEL=y127127+CONFIG_DEBUG_SHIRQ=y128128+CONFIG_DETECT_HUNG_TASK=y129129+CONFIG_DEBUG_INFO=y130130+CONFIG_DEBUG_VM=y131131+# CONFIG_RCU_CPU_STALL_DETECTOR is not set132132+CONFIG_DWARF_UNWINDER=y133133+# CONFIG_CRYPTO_ANSI_CPRNG is not set
+3
arch/sh/tools/mach-types
···99HIGHLANDER SH_HIGHLANDER1010RTS7751R2D SH_RTS7751R2D1111RSK SH_RSK1212+ALPHA_BOARD SH_ALPHA_BOARD12131314#1415# List of companion chips / MFDs.···6261POLARIS SH_POLARIS6362KFR2R09 SH_KFR2R096463ECOVEC SH_ECOVEC6464+APSH4A3A SH_APSH4A3A6565+APSH4AD0A SH_APSH4AD0A
+1
drivers/block/Kconfig
···464464 tristate "Xen virtual block device support"465465 depends on XEN466466 default y467467+ select XEN_XENBUS_FRONTEND467468 help468469 This driver implements the front-end of the Xen virtual469470 block device driver. It communicates with a back-end driver
···3535#include <linux/swap.h>3636#include <linux/pci.h>37373838-static void i915_gem_object_flush_gpu_write_domain(struct drm_i915_gem_object *obj);3838+static __must_check int i915_gem_object_flush_gpu_write_domain(struct drm_i915_gem_object *obj);3939static void i915_gem_object_flush_gtt_write_domain(struct drm_i915_gem_object *obj);4040static void i915_gem_object_flush_cpu_write_domain(struct drm_i915_gem_object *obj);4141-static int i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj,4242- bool write);4343-static int i915_gem_object_set_cpu_read_domain_range(struct drm_i915_gem_object *obj,4444- uint64_t offset,4545- uint64_t size);4141+static __must_check int i915_gem_object_set_to_cpu_domain(struct drm_i915_gem_object *obj,4242+ bool write);4343+static __must_check int i915_gem_object_set_cpu_read_domain_range(struct drm_i915_gem_object *obj,4444+ uint64_t offset,4545+ uint64_t size);4646static void i915_gem_object_set_to_full_cpu_read_domain(struct drm_i915_gem_object *obj);4747-static int i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,4848- unsigned alignment,4949- bool map_and_fenceable);4747+static __must_check int i915_gem_object_bind_to_gtt(struct drm_i915_gem_object *obj,4848+ unsigned alignment,4949+ bool map_and_fenceable);5050static void i915_gem_clear_fence_reg(struct drm_device *dev,5151 struct drm_i915_fence_reg *reg);5252static int i915_gem_phys_pwrite(struct drm_device *dev,···19351935{19361936 drm_i915_private_t *dev_priv;19371937 struct drm_device *dev;19381938+ bool idle;19391939+ int i;1938194019391941 dev_priv = container_of(work, drm_i915_private_t,19401942 mm.retire_work.work);···1950194819511949 i915_gem_retire_requests(dev);1952195019531953- if (!dev_priv->mm.suspended &&19541954- (!list_empty(&dev_priv->ring[RCS].request_list) ||19551955- !list_empty(&dev_priv->ring[VCS].request_list) ||19561956- !list_empty(&dev_priv->ring[BCS].request_list)))19511951+ /* Send a periodic flush down the ring so we don't hold onto GEM19521952+ * objects indefinitely.19531953+ */19541954+ idle = true;19551955+ for (i = 0; i < I915_NUM_RINGS; i++) {19561956+ struct intel_ring_buffer *ring = &dev_priv->ring[i];19571957+19581958+ if (!list_empty(&ring->gpu_write_list)) {19591959+ struct drm_i915_gem_request *request;19601960+ int ret;19611961+19621962+ ret = i915_gem_flush_ring(dev, ring, 0,19631963+ I915_GEM_GPU_DOMAINS);19641964+ request = kzalloc(sizeof(*request), GFP_KERNEL);19651965+ if (ret || request == NULL ||19661966+ i915_add_request(dev, NULL, request, ring))19671967+ kfree(request);19681968+ }19691969+19701970+ idle &= list_empty(&ring->request_list);19711971+ }19721972+19731973+ if (!dev_priv->mm.suspended && !idle)19571974 queue_delayed_work(dev_priv->wq, &dev_priv->mm.retire_work, HZ);19751975+19581976 mutex_unlock(&dev->struct_mutex);19591977}19601978···21642142 return ret;21652143}2166214421672167-void21452145+int21682146i915_gem_flush_ring(struct drm_device *dev,21692147 struct intel_ring_buffer *ring,21702148 uint32_t invalidate_domains,21712149 uint32_t flush_domains)21722150{21732173- ring->flush(ring, invalidate_domains, flush_domains);21512151+ int ret;21522152+21532153+ ret = ring->flush(ring, invalidate_domains, flush_domains);21542154+ if (ret)21552155+ return ret;21562156+21742157 i915_gem_process_flushing_list(dev, flush_domains, ring);21582158+ return 0;21752159}2176216021772161static int i915_ring_idle(struct drm_device *dev,21782162 struct intel_ring_buffer *ring)21792163{21642164+ int ret;21652165+21802166 if (list_empty(&ring->gpu_write_list) && list_empty(&ring->active_list))21812167 return 0;2182216821832183- if (!list_empty(&ring->gpu_write_list))21842184- i915_gem_flush_ring(dev, ring,21692169+ if (!list_empty(&ring->gpu_write_list)) {21702170+ ret = i915_gem_flush_ring(dev, ring,21852171 I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS);21722172+ if (ret)21732173+ return ret;21742174+ }21752175+21862176 return i915_wait_request(dev,21872177 i915_gem_next_request_seqno(dev, ring),21882178 ring);···24042370 int ret;2405237124062372 if (obj->fenced_gpu_access) {24072407- if (obj->base.write_domain & I915_GEM_GPU_DOMAINS)24082408- i915_gem_flush_ring(obj->base.dev,24092409- obj->last_fenced_ring,24102410- 0, obj->base.write_domain);23732373+ if (obj->base.write_domain & I915_GEM_GPU_DOMAINS) {23742374+ ret = i915_gem_flush_ring(obj->base.dev,23752375+ obj->last_fenced_ring,23762376+ 0, obj->base.write_domain);23772377+ if (ret)23782378+ return ret;23792379+ }2411238024122381 obj->fenced_gpu_access = false;24132382 }···24292392 obj->last_fenced_seqno = 0;24302393 obj->last_fenced_ring = NULL;24312394 }23952395+23962396+ /* Ensure that all CPU reads are completed before installing a fence23972397+ * and all writes before removing the fence.23982398+ */23992399+ if (obj->base.read_domains & I915_GEM_DOMAIN_GTT)24002400+ mb();2432240124332402 return 0;24342403}···25662523 return ret;25672524 } else if (obj->tiling_changed) {25682525 if (obj->fenced_gpu_access) {25692569- if (obj->base.write_domain & I915_GEM_GPU_DOMAINS)25702570- i915_gem_flush_ring(obj->base.dev, obj->ring,25712571- 0, obj->base.write_domain);25262526+ if (obj->base.write_domain & I915_GEM_GPU_DOMAINS) {25272527+ ret = i915_gem_flush_ring(obj->base.dev, obj->ring,25282528+ 0, obj->base.write_domain);25292529+ if (ret)25302530+ return ret;25312531+ }2572253225732533 obj->fenced_gpu_access = false;25742534 }···27822736 obj->gtt_space = NULL;2783273727842738 if (ret == -ENOMEM) {27852785- /* first try to clear up some space from the GTT */27862786- ret = i915_gem_evict_something(dev, size,27872787- alignment,27882788- map_and_fenceable);27392739+ /* first try to reclaim some memory by clearing the GTT */27402740+ ret = i915_gem_evict_everything(dev, false);27892741 if (ret) {27902742 /* now try to shrink everyone else */27912743 if (gfpmask) {···27912747 goto search_free;27922748 }2793274927942794- return ret;27502750+ return -ENOMEM;27952751 }2796275227972753 goto search_free;···28062762 drm_mm_put_block(obj->gtt_space);28072763 obj->gtt_space = NULL;2808276428092809- ret = i915_gem_evict_something(dev, size,28102810- alignment, map_and_fenceable);28112811- if (ret)27652765+ if (i915_gem_evict_everything(dev, false))28122766 return ret;2813276728142768 goto search_free;···28532811}2854281228552813/** Flushes any GPU write domain for the object if it's dirty. */28562856-static void28142814+static int28572815i915_gem_object_flush_gpu_write_domain(struct drm_i915_gem_object *obj)28582816{28592817 struct drm_device *dev = obj->base.dev;2860281828612819 if ((obj->base.write_domain & I915_GEM_GPU_DOMAINS) == 0)28622862- return;28202820+ return 0;2863282128642822 /* Queue the GPU write cache flushing we need. */28652865- i915_gem_flush_ring(dev, obj->ring, 0, obj->base.write_domain);28662866- BUG_ON(obj->base.write_domain);28232823+ return i915_gem_flush_ring(dev, obj->ring, 0, obj->base.write_domain);28672824}2868282528692826/** Flushes the GTT write domain for the object if it's dirty. */···28742833 if (obj->base.write_domain != I915_GEM_DOMAIN_GTT)28752834 return;2876283528772877- /* No actual flushing is required for the GTT write domain. Writes28362836+ /* No actual flushing is required for the GTT write domain. Writes28782837 * to it immediately go to main memory as far as we know, so there's28792838 * no chipset flush. It also doesn't land in render cache.28392839+ *28402840+ * However, we do have to enforce the order so that all writes through28412841+ * the GTT land before any writes to the device, such as updates to28422842+ * the GATT itself.28802843 */28442844+ wmb();28452845+28812846 i915_gem_release_mmap(obj);2882284728832848 old_write_domain = obj->base.write_domain;···29292882 if (obj->gtt_space == NULL)29302883 return -EINVAL;2931288429322932- i915_gem_object_flush_gpu_write_domain(obj);28852885+ ret = i915_gem_object_flush_gpu_write_domain(obj);28862886+ if (ret)28872887+ return ret;28882888+29332889 if (obj->pending_gpu_write || write) {29342890 ret = i915_gem_object_wait_rendering(obj, true);29352891 if (ret)···29772927 if (obj->gtt_space == NULL)29782928 return -EINVAL;2979292929802980- i915_gem_object_flush_gpu_write_domain(obj);29302930+ ret = i915_gem_object_flush_gpu_write_domain(obj);29312931+ if (ret)29322932+ return ret;29332933+2981293429822935 /* Currently, we are always called from an non-interruptible context. */29832936 if (pipelined != obj->ring) {···30052952i915_gem_object_flush_gpu(struct drm_i915_gem_object *obj,30062953 bool interruptible)30072954{29552955+ int ret;29562956+30082957 if (!obj->active)30092958 return 0;3010295930113011- if (obj->base.write_domain & I915_GEM_GPU_DOMAINS)30123012- i915_gem_flush_ring(obj->base.dev, obj->ring,30133013- 0, obj->base.write_domain);29602960+ if (obj->base.write_domain & I915_GEM_GPU_DOMAINS) {29612961+ ret = i915_gem_flush_ring(obj->base.dev, obj->ring,29622962+ 0, obj->base.write_domain);29632963+ if (ret)29642964+ return ret;29652965+ }3014296630152967 return i915_gem_object_wait_rendering(obj, interruptible);30162968}···30322974 uint32_t old_write_domain, old_read_domains;30332975 int ret;3034297630353035- i915_gem_object_flush_gpu_write_domain(obj);29772977+ ret = i915_gem_object_flush_gpu_write_domain(obj);29782978+ if (ret)29792979+ return ret;29802980+30362981 ret = i915_gem_object_wait_rendering(obj, true);30372982 if (ret)30382983 return ret;···31303069 if (offset == 0 && size == obj->base.size)31313070 return i915_gem_object_set_to_cpu_domain(obj, 0);3132307131333133- i915_gem_object_flush_gpu_write_domain(obj);30723072+ ret = i915_gem_object_flush_gpu_write_domain(obj);30733073+ if (ret)30743074+ return ret;30753075+31343076 ret = i915_gem_object_wait_rendering(obj, true);31353077 if (ret)31363078 return ret;···34263362 * flush earlier is beneficial.34273363 */34283364 if (obj->base.write_domain & I915_GEM_GPU_DOMAINS) {34293429- i915_gem_flush_ring(dev, obj->ring,34303430- 0, obj->base.write_domain);33653365+ ret = i915_gem_flush_ring(dev, obj->ring,33663366+ 0, obj->base.write_domain);34313367 } else if (obj->ring->outstanding_lazy_request ==34323368 obj->last_rendering_seqno) {34333369 struct drm_i915_gem_request *request;
+8-1
drivers/gpu/drm/i915/i915_gem_evict.c
···127127 }128128129129 /* Nothing found, clean up and bail out! */130130- list_for_each_entry(obj, &unwind_list, exec_list) {130130+ while (!list_empty(&unwind_list)) {131131+ obj = list_first_entry(&unwind_list,132132+ struct drm_i915_gem_object,133133+ exec_list);134134+131135 ret = drm_mm_scan_remove_block(obj->gtt_space);132136 BUG_ON(ret);137137+138138+ list_del_init(&obj->exec_list);133139 drm_gem_object_unreference(&obj->base);134140 }135141···168162 exec_list);169163 if (ret == 0)170164 ret = i915_gem_object_unbind(obj);165165+171166 list_del_init(&obj->exec_list);172167 drm_gem_object_unreference(&obj->base);173168 }
+75-44
drivers/gpu/drm/i915/i915_gem_execbuffer.c
···268268static int269269i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj,270270 struct eb_objects *eb,271271- struct drm_i915_gem_exec_object2 *entry,272271 struct drm_i915_gem_relocation_entry *reloc)273272{274273 struct drm_device *dev = obj->base.dev;···410411411412static int412413i915_gem_execbuffer_relocate_object(struct drm_i915_gem_object *obj,413413- struct eb_objects *eb,414414- struct drm_i915_gem_exec_object2 *entry)414414+ struct eb_objects *eb)415415{416416 struct drm_i915_gem_relocation_entry __user *user_relocs;417417+ struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;417418 int i, ret;418419419420 user_relocs = (void __user *)(uintptr_t)entry->relocs_ptr;···425426 sizeof(reloc)))426427 return -EFAULT;427428428428- ret = i915_gem_execbuffer_relocate_entry(obj, eb, entry, &reloc);429429+ ret = i915_gem_execbuffer_relocate_entry(obj, eb, &reloc);429430 if (ret)430431 return ret;431432···441442static int442443i915_gem_execbuffer_relocate_object_slow(struct drm_i915_gem_object *obj,443444 struct eb_objects *eb,444444- struct drm_i915_gem_exec_object2 *entry,445445 struct drm_i915_gem_relocation_entry *relocs)446446{447447+ const struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;447448 int i, ret;448449449450 for (i = 0; i < entry->relocation_count; i++) {450450- ret = i915_gem_execbuffer_relocate_entry(obj, eb, entry, &relocs[i]);451451+ ret = i915_gem_execbuffer_relocate_entry(obj, eb, &relocs[i]);451452 if (ret)452453 return ret;453454 }···458459static int459460i915_gem_execbuffer_relocate(struct drm_device *dev,460461 struct eb_objects *eb,461461- struct list_head *objects,462462- struct drm_i915_gem_exec_object2 *exec)462462+ struct list_head *objects)463463{464464 struct drm_i915_gem_object *obj;465465 int ret;···466468 list_for_each_entry(obj, objects, exec_list) {467469 obj->base.pending_read_domains = 0;468470 obj->base.pending_write_domain = 0;469469- ret = i915_gem_execbuffer_relocate_object(obj, eb, exec++);471471+ ret = i915_gem_execbuffer_relocate_object(obj, eb);470472 if (ret)471473 return ret;472474 }···477479static int478480i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,479481 struct drm_file *file,480480- struct list_head *objects,481481- struct drm_i915_gem_exec_object2 *exec)482482+ struct list_head *objects)482483{483484 struct drm_i915_gem_object *obj;484484- struct drm_i915_gem_exec_object2 *entry;485485 int ret, retry;486486 bool has_fenced_gpu_access = INTEL_INFO(ring->dev)->gen < 4;487487+ struct list_head ordered_objects;488488+489489+ INIT_LIST_HEAD(&ordered_objects);490490+ while (!list_empty(objects)) {491491+ struct drm_i915_gem_exec_object2 *entry;492492+ bool need_fence, need_mappable;493493+494494+ obj = list_first_entry(objects,495495+ struct drm_i915_gem_object,496496+ exec_list);497497+ entry = obj->exec_entry;498498+499499+ need_fence =500500+ has_fenced_gpu_access &&501501+ entry->flags & EXEC_OBJECT_NEEDS_FENCE &&502502+ obj->tiling_mode != I915_TILING_NONE;503503+ need_mappable =504504+ entry->relocation_count ? true : need_fence;505505+506506+ if (need_mappable)507507+ list_move(&obj->exec_list, &ordered_objects);508508+ else509509+ list_move_tail(&obj->exec_list, &ordered_objects);510510+ }511511+ list_splice(&ordered_objects, objects);487512488513 /* Attempt to pin all of the buffers into the GTT.489514 * This is done in 3 phases:···525504 ret = 0;526505527506 /* Unbind any ill-fitting objects or pin. */528528- entry = exec;529507 list_for_each_entry(obj, objects, exec_list) {508508+ struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;530509 bool need_fence, need_mappable;531531-532532- if (!obj->gtt_space) {533533- entry++;510510+ if (!obj->gtt_space)534511 continue;535535- }536512537513 need_fence =538514 has_fenced_gpu_access &&···552534 }553535554536 /* Bind fresh objects */555555- entry = exec;556537 list_for_each_entry(obj, objects, exec_list) {538538+ struct drm_i915_gem_exec_object2 *entry = obj->exec_entry;557539 bool need_fence;558540559541 need_fence =···588570 }589571590572 entry->offset = obj->gtt_offset;591591- entry++;592573 }593574594575 /* Decrement pin count for bound objects */···639622 int i, total, ret;640623641624 /* We may process another execbuffer during the unlock... */642642- while (list_empty(objects)) {625625+ while (!list_empty(objects)) {643626 obj = list_first_entry(objects,644627 struct drm_i915_gem_object,645628 exec_list);···682665 }683666684667 /* reacquire the objects */685685- INIT_LIST_HEAD(objects);686668 eb_reset(eb);687669 for (i = 0; i < count; i++) {688670 struct drm_i915_gem_object *obj;···697681698682 list_add_tail(&obj->exec_list, objects);699683 obj->exec_handle = exec[i].handle;684684+ obj->exec_entry = &exec[i];700685 eb_add_object(eb, obj);701686 }702687703703- ret = i915_gem_execbuffer_reserve(ring, file, objects, exec);688688+ ret = i915_gem_execbuffer_reserve(ring, file, objects);704689 if (ret)705690 goto err;706691···710693 obj->base.pending_read_domains = 0;711694 obj->base.pending_write_domain = 0;712695 ret = i915_gem_execbuffer_relocate_object_slow(obj, eb,713713- exec,714696 reloc + total);715697 if (ret)716698 goto err;···729713 return ret;730714}731715732732-static void716716+static int733717i915_gem_execbuffer_flush(struct drm_device *dev,734718 uint32_t invalidate_domains,735719 uint32_t flush_domains,736720 uint32_t flush_rings)737721{738722 drm_i915_private_t *dev_priv = dev->dev_private;739739- int i;723723+ int i, ret;740724741725 if (flush_domains & I915_GEM_DOMAIN_CPU)742726 intel_gtt_chipset_flush();743727728728+ if (flush_domains & I915_GEM_DOMAIN_GTT)729729+ wmb();730730+744731 if ((flush_domains | invalidate_domains) & I915_GEM_GPU_DOMAINS) {745732 for (i = 0; i < I915_NUM_RINGS; i++)746746- if (flush_rings & (1 << i))747747- i915_gem_flush_ring(dev, &dev_priv->ring[i],748748- invalidate_domains,749749- flush_domains);733733+ if (flush_rings & (1 << i)) {734734+ ret = i915_gem_flush_ring(dev,735735+ &dev_priv->ring[i],736736+ invalidate_domains,737737+ flush_domains);738738+ if (ret)739739+ return ret;740740+ }750741 }742742+743743+ return 0;751744}752745753746static int···820795 cd.invalidate_domains,821796 cd.flush_domains);822797#endif823823- i915_gem_execbuffer_flush(ring->dev,824824- cd.invalidate_domains,825825- cd.flush_domains,826826- cd.flush_rings);798798+ ret = i915_gem_execbuffer_flush(ring->dev,799799+ cd.invalidate_domains,800800+ cd.flush_domains,801801+ cd.flush_rings);802802+ if (ret)803803+ return ret;827804 }828805829806 list_for_each_entry(obj, objects, exec_list) {···948921 struct intel_ring_buffer *ring)949922{950923 struct drm_i915_gem_request *request;951951- u32 flush_domains;924924+ u32 invalidate;952925953926 /*954927 * Ensure that the commands in the batch buffer are···956929 *957930 * The sampler always gets flushed on i965 (sigh).958931 */959959- flush_domains = 0;932932+ invalidate = I915_GEM_DOMAIN_COMMAND;960933 if (INTEL_INFO(dev)->gen >= 4)961961- flush_domains |= I915_GEM_DOMAIN_SAMPLER;962962-963963- ring->flush(ring, I915_GEM_DOMAIN_COMMAND, flush_domains);934934+ invalidate |= I915_GEM_DOMAIN_SAMPLER;935935+ if (ring->flush(ring, invalidate, 0)) {936936+ i915_gem_next_request_seqno(dev, ring);937937+ return;938938+ }964939965940 /* Add a breadcrumb for the completion of the batch buffer */966941 request = kzalloc(sizeof(*request), GFP_KERNEL);···1127109811281099 list_add_tail(&obj->exec_list, &objects);11291100 obj->exec_handle = exec[i].handle;11011101+ obj->exec_entry = &exec[i];11301102 eb_add_object(eb, obj);11311103 }1132110411051105+ /* take note of the batch buffer before we might reorder the lists */11061106+ batch_obj = list_entry(objects.prev,11071107+ struct drm_i915_gem_object,11081108+ exec_list);11091109+11331110 /* Move the objects en-masse into the GTT, evicting if necessary. */11341134- ret = i915_gem_execbuffer_reserve(ring, file, &objects, exec);11111111+ ret = i915_gem_execbuffer_reserve(ring, file, &objects);11351112 if (ret)11361113 goto err;1137111411381115 /* The objects are in their final locations, apply the relocations. */11391139- ret = i915_gem_execbuffer_relocate(dev, eb, &objects, exec);11161116+ ret = i915_gem_execbuffer_relocate(dev, eb, &objects);11401117 if (ret) {11411118 if (ret == -EFAULT) {11421119 ret = i915_gem_execbuffer_relocate_slow(dev, file, ring,···11561121 }1157112211581123 /* Set the pending read domains for the batch buffer to COMMAND */11591159- batch_obj = list_entry(objects.prev,11601160- struct drm_i915_gem_object,11611161- exec_list);11621124 if (batch_obj->base.pending_write_domain) {11631125 DRM_ERROR("Attempting to use self-modifying batch buffer\n");11641126 ret = -EINVAL;···13721340 drm_free_large(exec2_list);13731341 return ret;13741342}13751375-
···3030#include "drm.h"3131#include "drm_crtc.h"3232#include "drm_crtc_helper.h"3333+#include "drm_edid.h"3334#include "intel_drv.h"3435#include "i915_drm.h"3536#include "i915_drv.h"···288287 return i2c_transfer(&dev_priv->gmbus[ddc_bus].adapter, msgs, 1) == 1;289288}290289291291-static bool intel_crt_detect_ddc(struct intel_crt *crt)290290+static bool intel_crt_detect_ddc(struct drm_connector *connector)292291{292292+ struct intel_crt *crt = intel_attached_crt(connector);293293 struct drm_i915_private *dev_priv = crt->base.base.dev->dev_private;294294295295 /* CRT should always be at 0, but check anyway */···303301 }304302305303 if (intel_ddc_probe(&crt->base, dev_priv->crt_ddc_pin)) {306306- DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");307307- return true;304304+ struct edid *edid;305305+ bool is_digital = false;306306+307307+ edid = drm_get_edid(connector,308308+ &dev_priv->gmbus[dev_priv->crt_ddc_pin].adapter);309309+ /*310310+ * This may be a DVI-I connector with a shared DDC311311+ * link between analog and digital outputs, so we312312+ * have to check the EDID input spec of the attached device.313313+ */314314+ if (edid != NULL) {315315+ is_digital = edid->input & DRM_EDID_INPUT_DIGITAL;316316+ connector->display_info.raw_edid = NULL;317317+ kfree(edid);318318+ }319319+320320+ if (!is_digital) {321321+ DRM_DEBUG_KMS("CRT detected via DDC:0x50 [EDID]\n");322322+ return true;323323+ }308324 }309325310326 return false;···478458 }479459 }480460481481- if (intel_crt_detect_ddc(crt))461461+ if (intel_crt_detect_ddc(connector))482462 return connector_status_connected;483463484464 if (!force)···492472 crtc = intel_get_load_detect_pipe(&crt->base, connector,493473 NULL, &dpms_mode);494474 if (crtc) {495495- if (intel_crt_detect_ddc(crt))475475+ if (intel_crt_detect_ddc(connector))496476 status = connector_status_connected;497477 else498478 status = intel_crt_load_detect(crtc, crt);
+269-207
drivers/gpu/drm/i915/intel_display.c
···34183418static bool ironlake_compute_wm0(struct drm_device *dev,34193419 int pipe,34203420 const struct intel_watermark_params *display,34213421- int display_latency,34213421+ int display_latency_ns,34223422 const struct intel_watermark_params *cursor,34233423- int cursor_latency,34233423+ int cursor_latency_ns,34243424 int *plane_wm,34253425 int *cursor_wm)34263426{34273427 struct drm_crtc *crtc;34283428- int htotal, hdisplay, clock, pixel_size = 0;34293429- int line_time_us, line_count, entries;34283428+ int htotal, hdisplay, clock, pixel_size;34293429+ int line_time_us, line_count;34303430+ int entries, tlb_miss;3430343134313432 crtc = intel_get_crtc_for_pipe(dev, pipe);34323433 if (crtc->fb == NULL || !crtc->enabled)···34393438 pixel_size = crtc->fb->bits_per_pixel / 8;3440343934413440 /* Use the small buffer method to calculate plane watermark */34423442- entries = ((clock * pixel_size / 1000) * display_latency * 100) / 1000;34413441+ entries = ((clock * pixel_size / 1000) * display_latency_ns) / 1000;34423442+ tlb_miss = display->fifo_size*display->cacheline_size - hdisplay * 8;34433443+ if (tlb_miss > 0)34443444+ entries += tlb_miss;34433445 entries = DIV_ROUND_UP(entries, display->cacheline_size);34443446 *plane_wm = entries + display->guard_size;34453447 if (*plane_wm > (int)display->max_wm)···3450344634513447 /* Use the large buffer method to calculate cursor watermark */34523448 line_time_us = ((htotal * 1000) / clock);34533453- line_count = (cursor_latency * 100 / line_time_us + 1000) / 1000;34493449+ line_count = (cursor_latency_ns / line_time_us + 1000) / 1000;34543450 entries = line_count * 64 * pixel_size;34513451+ tlb_miss = cursor->fifo_size*cursor->cacheline_size - hdisplay * 8;34523452+ if (tlb_miss > 0)34533453+ entries += tlb_miss;34553454 entries = DIV_ROUND_UP(entries, cursor->cacheline_size);34563455 *cursor_wm = entries + cursor->guard_size;34573456 if (*cursor_wm > (int)cursor->max_wm)···34633456 return true;34643457}3465345834593459+/*34603460+ * Check the wm result.34613461+ *34623462+ * If any calculated watermark values is larger than the maximum value that34633463+ * can be programmed into the associated watermark register, that watermark34643464+ * must be disabled.34653465+ */34663466+static bool ironlake_check_srwm(struct drm_device *dev, int level,34673467+ int fbc_wm, int display_wm, int cursor_wm,34683468+ const struct intel_watermark_params *display,34693469+ const struct intel_watermark_params *cursor)34703470+{34713471+ struct drm_i915_private *dev_priv = dev->dev_private;34723472+34733473+ DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"34743474+ " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);34753475+34763476+ if (fbc_wm > SNB_FBC_MAX_SRWM) {34773477+ DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",34783478+ fbc_wm, SNB_FBC_MAX_SRWM, level);34793479+34803480+ /* fbc has it's own way to disable FBC WM */34813481+ I915_WRITE(DISP_ARB_CTL,34823482+ I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);34833483+ return false;34843484+ }34853485+34863486+ if (display_wm > display->max_wm) {34873487+ DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",34883488+ display_wm, SNB_DISPLAY_MAX_SRWM, level);34893489+ return false;34903490+ }34913491+34923492+ if (cursor_wm > cursor->max_wm) {34933493+ DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",34943494+ cursor_wm, SNB_CURSOR_MAX_SRWM, level);34953495+ return false;34963496+ }34973497+34983498+ if (!(fbc_wm || display_wm || cursor_wm)) {34993499+ DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);35003500+ return false;35013501+ }35023502+35033503+ return true;35043504+}35053505+35063506+/*35073507+ * Compute watermark values of WM[1-3],35083508+ */35093509+static bool ironlake_compute_srwm(struct drm_device *dev, int level,35103510+ int hdisplay, int htotal,35113511+ int pixel_size, int clock, int latency_ns,35123512+ const struct intel_watermark_params *display,35133513+ const struct intel_watermark_params *cursor,35143514+ int *fbc_wm, int *display_wm, int *cursor_wm)35153515+{35163516+35173517+ unsigned long line_time_us;35183518+ int line_count, line_size;35193519+ int small, large;35203520+ int entries;35213521+35223522+ if (!latency_ns) {35233523+ *fbc_wm = *display_wm = *cursor_wm = 0;35243524+ return false;35253525+ }35263526+35273527+ line_time_us = (htotal * 1000) / clock;35283528+ line_count = (latency_ns / line_time_us + 1000) / 1000;35293529+ line_size = hdisplay * pixel_size;35303530+35313531+ /* Use the minimum of the small and large buffer method for primary */35323532+ small = ((clock * pixel_size / 1000) * latency_ns) / 1000;35333533+ large = line_count * line_size;35343534+35353535+ entries = DIV_ROUND_UP(min(small, large), display->cacheline_size);35363536+ *display_wm = entries + display->guard_size;35373537+35383538+ /*35393539+ * Spec says:35403540+ * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 235413541+ */35423542+ *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;35433543+35443544+ /* calculate the self-refresh watermark for display cursor */35453545+ entries = line_count * pixel_size * 64;35463546+ entries = DIV_ROUND_UP(entries, cursor->cacheline_size);35473547+ *cursor_wm = entries + cursor->guard_size;35483548+35493549+ return ironlake_check_srwm(dev, level,35503550+ *fbc_wm, *display_wm, *cursor_wm,35513551+ display, cursor);35523552+}35533553+34663554static void ironlake_update_wm(struct drm_device *dev,34673555 int planea_clock, int planeb_clock,34683468- int sr_hdisplay, int sr_htotal,35563556+ int hdisplay, int htotal,34693557 int pixel_size)34703558{34713559 struct drm_i915_private *dev_priv = dev->dev_private;34723472- int plane_wm, cursor_wm, enabled;34733473- int tmp;35603560+ int fbc_wm, plane_wm, cursor_wm, enabled;35613561+ int clock;3474356234753563 enabled = 0;34763564 if (ironlake_compute_wm0(dev, 0,···36003498 * Calculate and update the self-refresh watermark only when one36013499 * display plane is used.36023500 */36033603- tmp = 0;36043604- if (enabled == 1) {36053605- unsigned long line_time_us;36063606- int small, large, plane_fbc;36073607- int sr_clock, entries;36083608- int line_count, line_size;36093609- /* Read the self-refresh latency. The unit is 0.5us */36103610- int ilk_sr_latency = I915_READ(MLTR_ILK) & ILK_SRLT_MASK;35013501+ I915_WRITE(WM3_LP_ILK, 0);35023502+ I915_WRITE(WM2_LP_ILK, 0);35033503+ I915_WRITE(WM1_LP_ILK, 0);3611350436123612- sr_clock = planea_clock ? planea_clock : planeb_clock;36133613- line_time_us = (sr_htotal * 1000) / sr_clock;35053505+ if (enabled != 1)35063506+ return;3614350736153615- /* Use ns/us then divide to preserve precision */36163616- line_count = ((ilk_sr_latency * 500) / line_time_us + 1000)36173617- / 1000;36183618- line_size = sr_hdisplay * pixel_size;35083508+ clock = planea_clock ? planea_clock : planeb_clock;3619350936203620- /* Use the minimum of the small and large buffer method for primary */36213621- small = ((sr_clock * pixel_size / 1000) * (ilk_sr_latency * 500)) / 1000;36223622- large = line_count * line_size;35103510+ /* WM1 */35113511+ if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size,35123512+ clock, ILK_READ_WM1_LATENCY() * 500,35133513+ &ironlake_display_srwm_info,35143514+ &ironlake_cursor_srwm_info,35153515+ &fbc_wm, &plane_wm, &cursor_wm))35163516+ return;3623351736243624- entries = DIV_ROUND_UP(min(small, large),36253625- ironlake_display_srwm_info.cacheline_size);35183518+ I915_WRITE(WM1_LP_ILK,35193519+ WM1_LP_SR_EN |35203520+ (ILK_READ_WM1_LATENCY() << WM1_LP_LATENCY_SHIFT) |35213521+ (fbc_wm << WM1_LP_FBC_SHIFT) |35223522+ (plane_wm << WM1_LP_SR_SHIFT) |35233523+ cursor_wm);3626352436273627- plane_fbc = entries * 64;36283628- plane_fbc = DIV_ROUND_UP(plane_fbc, line_size);35253525+ /* WM2 */35263526+ if (!ironlake_compute_srwm(dev, 2, hdisplay, htotal, pixel_size,35273527+ clock, ILK_READ_WM2_LATENCY() * 500,35283528+ &ironlake_display_srwm_info,35293529+ &ironlake_cursor_srwm_info,35303530+ &fbc_wm, &plane_wm, &cursor_wm))35313531+ return;3629353236303630- plane_wm = entries + ironlake_display_srwm_info.guard_size;36313631- if (plane_wm > (int)ironlake_display_srwm_info.max_wm)36323632- plane_wm = ironlake_display_srwm_info.max_wm;36333633-36343634- /* calculate the self-refresh watermark for display cursor */36353635- entries = line_count * pixel_size * 64;36363636- entries = DIV_ROUND_UP(entries,36373637- ironlake_cursor_srwm_info.cacheline_size);36383638-36393639- cursor_wm = entries + ironlake_cursor_srwm_info.guard_size;36403640- if (cursor_wm > (int)ironlake_cursor_srwm_info.max_wm)36413641- cursor_wm = ironlake_cursor_srwm_info.max_wm;36423642-36433643- /* configure watermark and enable self-refresh */36443644- tmp = (WM1_LP_SR_EN |36453645- (ilk_sr_latency << WM1_LP_LATENCY_SHIFT) |36463646- (plane_fbc << WM1_LP_FBC_SHIFT) |36473647- (plane_wm << WM1_LP_SR_SHIFT) |36483648- cursor_wm);36493649- DRM_DEBUG_KMS("self-refresh watermark: display plane %d, fbc lines %d,"36503650- " cursor %d\n", plane_wm, plane_fbc, cursor_wm);36513651- }36523652- I915_WRITE(WM1_LP_ILK, tmp);36533653- /* XXX setup WM2 and WM3 */36543654-}36553655-36563656-/*36573657- * Check the wm result.36583658- *36593659- * If any calculated watermark values is larger than the maximum value that36603660- * can be programmed into the associated watermark register, that watermark36613661- * must be disabled.36623662- *36633663- * Also return true if all of those watermark values is 0, which is set by36643664- * sandybridge_compute_srwm, to indicate the latency is ZERO.36653665- */36663666-static bool sandybridge_check_srwm(struct drm_device *dev, int level,36673667- int fbc_wm, int display_wm, int cursor_wm)36683668-{36693669- struct drm_i915_private *dev_priv = dev->dev_private;36703670-36713671- DRM_DEBUG_KMS("watermark %d: display plane %d, fbc lines %d,"36723672- " cursor %d\n", level, display_wm, fbc_wm, cursor_wm);36733673-36743674- if (fbc_wm > SNB_FBC_MAX_SRWM) {36753675- DRM_DEBUG_KMS("fbc watermark(%d) is too large(%d), disabling wm%d+\n",36763676- fbc_wm, SNB_FBC_MAX_SRWM, level);36773677-36783678- /* fbc has it's own way to disable FBC WM */36793679- I915_WRITE(DISP_ARB_CTL,36803680- I915_READ(DISP_ARB_CTL) | DISP_FBC_WM_DIS);36813681- return false;36823682- }36833683-36843684- if (display_wm > SNB_DISPLAY_MAX_SRWM) {36853685- DRM_DEBUG_KMS("display watermark(%d) is too large(%d), disabling wm%d+\n",36863686- display_wm, SNB_DISPLAY_MAX_SRWM, level);36873687- return false;36883688- }36893689-36903690- if (cursor_wm > SNB_CURSOR_MAX_SRWM) {36913691- DRM_DEBUG_KMS("cursor watermark(%d) is too large(%d), disabling wm%d+\n",36923692- cursor_wm, SNB_CURSOR_MAX_SRWM, level);36933693- return false;36943694- }36953695-36963696- if (!(fbc_wm || display_wm || cursor_wm)) {36973697- DRM_DEBUG_KMS("latency %d is 0, disabling wm%d+\n", level, level);36983698- return false;36993699- }37003700-37013701- return true;37023702-}37033703-37043704-/*37053705- * Compute watermark values of WM[1-3],37063706- */37073707-static bool sandybridge_compute_srwm(struct drm_device *dev, int level,37083708- int hdisplay, int htotal, int pixel_size,37093709- int clock, int latency_ns, int *fbc_wm,37103710- int *display_wm, int *cursor_wm)37113711-{37123712-37133713- unsigned long line_time_us;37143714- int small, large;37153715- int entries;37163716- int line_count, line_size;37173717-37183718- if (!latency_ns) {37193719- *fbc_wm = *display_wm = *cursor_wm = 0;37203720- return false;37213721- }37223722-37233723- line_time_us = (htotal * 1000) / clock;37243724- line_count = (latency_ns / line_time_us + 1000) / 1000;37253725- line_size = hdisplay * pixel_size;37263726-37273727- /* Use the minimum of the small and large buffer method for primary */37283728- small = ((clock * pixel_size / 1000) * latency_ns) / 1000;37293729- large = line_count * line_size;37303730-37313731- entries = DIV_ROUND_UP(min(small, large),37323732- sandybridge_display_srwm_info.cacheline_size);37333733- *display_wm = entries + sandybridge_display_srwm_info.guard_size;35333533+ I915_WRITE(WM2_LP_ILK,35343534+ WM2_LP_EN |35353535+ (ILK_READ_WM2_LATENCY() << WM1_LP_LATENCY_SHIFT) |35363536+ (fbc_wm << WM1_LP_FBC_SHIFT) |35373537+ (plane_wm << WM1_LP_SR_SHIFT) |35383538+ cursor_wm);3734353937353540 /*37363736- * Spec said:37373737- * FBC WM = ((Final Primary WM * 64) / number of bytes per line) + 235413541+ * WM3 is unsupported on ILK, probably because we don't have latency35423542+ * data for that power state37383543 */37393739- *fbc_wm = DIV_ROUND_UP(*display_wm * 64, line_size) + 2;37403740-37413741- /* calculate the self-refresh watermark for display cursor */37423742- entries = line_count * pixel_size * 64;37433743- entries = DIV_ROUND_UP(entries,37443744- sandybridge_cursor_srwm_info.cacheline_size);37453745- *cursor_wm = entries + sandybridge_cursor_srwm_info.guard_size;37463746-37473747- return sandybridge_check_srwm(dev, level,37483748- *fbc_wm, *display_wm, *cursor_wm);37493544}3750354537513546static void sandybridge_update_wm(struct drm_device *dev,···36513652 int pixel_size)36523653{36533654 struct drm_i915_private *dev_priv = dev->dev_private;36543654- int latency = SNB_READ_WM0_LATENCY();36553655+ int latency = SNB_READ_WM0_LATENCY() * 100; /* In unit 0.1us */36553656 int fbc_wm, plane_wm, cursor_wm, enabled;36563657 int clock;36573658···37003701 clock = planea_clock ? planea_clock : planeb_clock;3701370237023703 /* WM1 */37033703- if (!sandybridge_compute_srwm(dev, 1, hdisplay, htotal, pixel_size,37043704- clock, SNB_READ_WM1_LATENCY() * 500,37053705- &fbc_wm, &plane_wm, &cursor_wm))37043704+ if (!ironlake_compute_srwm(dev, 1, hdisplay, htotal, pixel_size,37053705+ clock, SNB_READ_WM1_LATENCY() * 500,37063706+ &sandybridge_display_srwm_info,37073707+ &sandybridge_cursor_srwm_info,37083708+ &fbc_wm, &plane_wm, &cursor_wm))37063709 return;3707371037083711 I915_WRITE(WM1_LP_ILK,···37153714 cursor_wm);3716371537173716 /* WM2 */37183718- if (!sandybridge_compute_srwm(dev, 2,37193719- hdisplay, htotal, pixel_size,37203720- clock, SNB_READ_WM2_LATENCY() * 500,37213721- &fbc_wm, &plane_wm, &cursor_wm))37173717+ if (!ironlake_compute_srwm(dev, 2,37183718+ hdisplay, htotal, pixel_size,37193719+ clock, SNB_READ_WM2_LATENCY() * 500,37203720+ &sandybridge_display_srwm_info,37213721+ &sandybridge_cursor_srwm_info,37223722+ &fbc_wm, &plane_wm, &cursor_wm))37223723 return;3723372437243725 I915_WRITE(WM2_LP_ILK,···37313728 cursor_wm);3732372937333730 /* WM3 */37343734- if (!sandybridge_compute_srwm(dev, 3,37353735- hdisplay, htotal, pixel_size,37363736- clock, SNB_READ_WM3_LATENCY() * 500,37373737- &fbc_wm, &plane_wm, &cursor_wm))37313731+ if (!ironlake_compute_srwm(dev, 3,37323732+ hdisplay, htotal, pixel_size,37333733+ clock, SNB_READ_WM3_LATENCY() * 500,37343734+ &sandybridge_display_srwm_info,37353735+ &sandybridge_cursor_srwm_info,37363736+ &fbc_wm, &plane_wm, &cursor_wm))37383737 return;3739373837403739 I915_WRITE(WM3_LP_ILK,···39563951 int lane = 0, link_bw, bpp;39573952 /* CPU eDP doesn't require FDI link, so just set DP M/N39583953 according to current link config */39593959- if (has_edp_encoder && !intel_encoder_is_pch_edp(&encoder->base)) {39543954+ if (has_edp_encoder && !intel_encoder_is_pch_edp(&has_edp_encoder->base)) {39603955 target_clock = mode->clock;39613956 intel_edp_link_config(has_edp_encoder,39623957 &lane, &link_bw);···50435038 drm_i915_private_t *dev_priv = dev->dev_private;50445039 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);50455040 int pipe = intel_crtc->pipe;50465046- int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;50475047- int dpll = I915_READ(dpll_reg);50415041+ int dpll_reg = DPLL(pipe);50425042+ int dpll;5048504350495044 if (HAS_PCH_SPLIT(dev))50505045 return;···50525047 if (!dev_priv->lvds_downclock_avail)50535048 return;5054504950505050+ dpll = I915_READ(dpll_reg);50555051 if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {50565052 DRM_DEBUG_DRIVER("upclocking LVDS\n");5057505350585054 /* Unlock panel regs */50595059- I915_WRITE(PP_CONTROL, I915_READ(PP_CONTROL) |50605060- PANEL_UNLOCK_REGS);50555055+ I915_WRITE(PP_CONTROL,50565056+ I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);5061505750625058 dpll &= ~DISPLAY_RATE_SELECT_FPA1;50635059 I915_WRITE(dpll_reg, dpll);50645064- dpll = I915_READ(dpll_reg);50605060+ POSTING_READ(dpll_reg);50655061 intel_wait_for_vblank(dev, pipe);50625062+50665063 dpll = I915_READ(dpll_reg);50675064 if (dpll & DISPLAY_RATE_SELECT_FPA1)50685065 DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");···58095802 encoder->base.possible_clones =58105803 intel_encoder_clones(dev, encoder->clone_mask);58115804 }58055805+58065806+ intel_panel_setup_backlight(dev);58125807}5813580858145809static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)···6154614561556146void gen6_enable_rps(struct drm_i915_private *dev_priv)61566147{61486148+ u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);61496149+ u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);61506150+ u32 pcu_mbox;61516151+ int cur_freq, min_freq, max_freq;61576152 int i;6158615361596154 /* Here begins a magic sequence of register writes to enable···62286215 if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,62296216 500))62306217 DRM_ERROR("timeout waiting for pcode mailbox to finish\n");62186218+62196219+ min_freq = (rp_state_cap & 0xff0000) >> 16;62206220+ max_freq = rp_state_cap & 0xff;62216221+ cur_freq = (gt_perf_status & 0xff00) >> 8;62226222+62236223+ /* Check for overclock support */62246224+ if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,62256225+ 500))62266226+ DRM_ERROR("timeout waiting for pcode mailbox to become idle\n");62276227+ I915_WRITE(GEN6_PCODE_MAILBOX, GEN6_READ_OC_PARAMS);62286228+ pcu_mbox = I915_READ(GEN6_PCODE_DATA);62296229+ if (wait_for((I915_READ(GEN6_PCODE_MAILBOX) & GEN6_PCODE_READY) == 0,62306230+ 500))62316231+ DRM_ERROR("timeout waiting for pcode mailbox to finish\n");62326232+ if (pcu_mbox & (1<<31)) { /* OC supported */62336233+ max_freq = pcu_mbox & 0xff;62346234+ DRM_DEBUG_DRIVER("overclocking supported, adjusting frequency max to %dMHz\n", pcu_mbox * 100);62356235+ }62366236+62376237+ /* In units of 100MHz */62386238+ dev_priv->max_delay = max_freq;62396239+ dev_priv->min_delay = min_freq;62406240+ dev_priv->cur_delay = cur_freq;6231624162326242 /* requires MSI enabled */62336243 I915_WRITE(GEN6_PMIER,···64226386 } else if (IS_I830(dev)) {64236387 I915_WRITE(DSPCLK_GATE_D, OVRUNIT_CLOCK_GATE_DISABLE);64246388 }64256425-64266426- /*64276427- * GPU can automatically power down the render unit if given a page64286428- * to save state.64296429- */64306430- if (IS_IRONLAKE_M(dev) && 0) { /* XXX causes a failure during suspend */64316431- if (dev_priv->renderctx == NULL)64326432- dev_priv->renderctx = intel_alloc_context_page(dev);64336433- if (dev_priv->renderctx) {64346434- struct drm_i915_gem_object *obj = dev_priv->renderctx;64356435- if (BEGIN_LP_RING(4) == 0) {64366436- OUT_RING(MI_SET_CONTEXT);64376437- OUT_RING(obj->gtt_offset |64386438- MI_MM_SPACE_GTT |64396439- MI_SAVE_EXT_STATE_EN |64406440- MI_RESTORE_EXT_STATE_EN |64416441- MI_RESTORE_INHIBIT);64426442- OUT_RING(MI_NOOP);64436443- OUT_RING(MI_FLUSH);64446444- ADVANCE_LP_RING();64456445- }64466446- } else64476447- DRM_DEBUG_KMS("Failed to allocate render context."64486448- "Disable RC6\n");64496449- }64506450-64516451- if (IS_GEN4(dev) && IS_MOBILE(dev)) {64526452- if (dev_priv->pwrctx == NULL)64536453- dev_priv->pwrctx = intel_alloc_context_page(dev);64546454- if (dev_priv->pwrctx) {64556455- struct drm_i915_gem_object *obj = dev_priv->pwrctx;64566456- I915_WRITE(PWRCTXA, obj->gtt_offset | PWRCTX_EN);64576457- I915_WRITE(MCHBAR_RENDER_STANDBY,64586458- I915_READ(MCHBAR_RENDER_STANDBY) & ~RCX_SW_EXIT);64596459- }64606460- }64616389}6462639064636391void intel_disable_clock_gating(struct drm_device *dev)···64496449 drm_gem_object_unreference(&obj->base);64506450 dev_priv->pwrctx = NULL;64516451 }64526452+}64536453+64546454+static void ironlake_disable_rc6(struct drm_device *dev)64556455+{64566456+ struct drm_i915_private *dev_priv = dev->dev_private;64576457+64586458+ /* Wake the GPU, prevent RC6, then restore RSTDBYCTL */64596459+ I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) | RCX_SW_EXIT);64606460+ wait_for(((I915_READ(RSTDBYCTL) & RSX_STATUS_MASK) == RSX_STATUS_ON),64616461+ 10);64626462+ POSTING_READ(CCID);64636463+ I915_WRITE(PWRCTXA, 0);64646464+ POSTING_READ(PWRCTXA);64656465+ I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);64666466+ POSTING_READ(RSTDBYCTL);64676467+ i915_gem_object_unpin(dev_priv->renderctx);64686468+ drm_gem_object_unreference(&dev_priv->renderctx->base);64696469+ dev_priv->renderctx = NULL;64706470+ i915_gem_object_unpin(dev_priv->pwrctx);64716471+ drm_gem_object_unreference(&dev_priv->pwrctx->base);64726472+ dev_priv->pwrctx = NULL;64736473+}64746474+64756475+void ironlake_enable_rc6(struct drm_device *dev)64766476+{64776477+ struct drm_i915_private *dev_priv = dev->dev_private;64786478+ int ret;64796479+64806480+ /*64816481+ * GPU can automatically power down the render unit if given a page64826482+ * to save state.64836483+ */64846484+ ret = BEGIN_LP_RING(6);64856485+ if (ret) {64866486+ ironlake_disable_rc6(dev);64876487+ return;64886488+ }64896489+ OUT_RING(MI_SUSPEND_FLUSH | MI_SUSPEND_FLUSH_EN);64906490+ OUT_RING(MI_SET_CONTEXT);64916491+ OUT_RING(dev_priv->renderctx->gtt_offset |64926492+ MI_MM_SPACE_GTT |64936493+ MI_SAVE_EXT_STATE_EN |64946494+ MI_RESTORE_EXT_STATE_EN |64956495+ MI_RESTORE_INHIBIT);64966496+ OUT_RING(MI_SUSPEND_FLUSH);64976497+ OUT_RING(MI_NOOP);64986498+ OUT_RING(MI_FLUSH);64996499+ ADVANCE_LP_RING();65006500+65016501+ I915_WRITE(PWRCTXA, dev_priv->pwrctx->gtt_offset | PWRCTX_EN);65026502+ I915_WRITE(RSTDBYCTL, I915_READ(RSTDBYCTL) & ~RCX_SW_EXIT);64526503}6453650464546505/* Set up chip specific display functions */···67166665 dev->mode_config.max_width = 8192;67176666 dev->mode_config.max_height = 8192;67186667 }67196719-67206720- /* set memory base */67216721- if (IS_GEN2(dev))67226722- dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);67236723- else67246724- dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);66686668+ dev->mode_config.fb_base = dev->agp->base;6725666967266670 if (IS_MOBILE(dev) || !IS_GEN2(dev))67276671 dev_priv->num_pipe = 2;···67446698 if (IS_GEN6(dev))67456699 gen6_enable_rps(dev_priv);6746670067016701+ if (IS_IRONLAKE_M(dev)) {67026702+ dev_priv->renderctx = intel_alloc_context_page(dev);67036703+ if (!dev_priv->renderctx)67046704+ goto skip_rc6;67056705+ dev_priv->pwrctx = intel_alloc_context_page(dev);67066706+ if (!dev_priv->pwrctx) {67076707+ i915_gem_object_unpin(dev_priv->renderctx);67086708+ drm_gem_object_unreference(&dev_priv->renderctx->base);67096709+ dev_priv->renderctx = NULL;67106710+ goto skip_rc6;67116711+ }67126712+ ironlake_enable_rc6(dev);67136713+ }67146714+67156715+skip_rc6:67476716 INIT_WORK(&dev_priv->idle_work, intel_idle_update);67486717 setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer,67496718 (unsigned long)dev);···67956734 if (IS_GEN6(dev))67966735 gen6_disable_rps(dev);6797673667986798- intel_disable_clock_gating(dev);67376737+ if (IS_IRONLAKE_M(dev))67386738+ ironlake_disable_rc6(dev);6799673968006740 mutex_unlock(&dev->struct_mutex);68016741
+39-11
drivers/gpu/drm/i915/intel_dp.c
···11531153static uint32_t11541154intel_gen6_edp_signal_levels(uint8_t train_set)11551155{11561156- switch (train_set & (DP_TRAIN_VOLTAGE_SWING_MASK|DP_TRAIN_PRE_EMPHASIS_MASK)) {11561156+ int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |11571157+ DP_TRAIN_PRE_EMPHASIS_MASK);11581158+ switch (signal_levels) {11571159 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:11581158- return EDP_LINK_TRAIN_400MV_0DB_SNB_B;11601160+ case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:11611161+ return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;11621162+ case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:11631163+ return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;11591164 case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:11601160- return EDP_LINK_TRAIN_400MV_6DB_SNB_B;11651165+ case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:11661166+ return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;11611167 case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:11621162- return EDP_LINK_TRAIN_600MV_3_5DB_SNB_B;11681168+ case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:11691169+ return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;11631170 case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:11641164- return EDP_LINK_TRAIN_800MV_0DB_SNB_B;11711171+ case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:11721172+ return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;11651173 default:11661166- DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level\n");11671167- return EDP_LINK_TRAIN_400MV_0DB_SNB_B;11741174+ DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"11751175+ "0x%x\n", signal_levels);11761176+ return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;11681177 }11691178}11701179···13431334 struct drm_device *dev = intel_dp->base.base.dev;13441335 struct drm_i915_private *dev_priv = dev->dev_private;13451336 bool channel_eq = false;13461346- int tries;13371337+ int tries, cr_tries;13471338 u32 reg;13481339 uint32_t DP = intel_dp->DP;1349134013501341 /* channel equalization */13511342 tries = 0;13431343+ cr_tries = 0;13521344 channel_eq = false;13531345 for (;;) {13541346 /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */13551347 uint32_t signal_levels;13481348+13491349+ if (cr_tries > 5) {13501350+ DRM_ERROR("failed to train DP, aborting\n");13511351+ intel_dp_link_down(intel_dp);13521352+ break;13531353+ }1356135413571355 if (IS_GEN6(dev) && is_edp(intel_dp)) {13581356 signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);···13831367 if (!intel_dp_get_link_status(intel_dp))13841368 break;1385136913701370+ /* Make sure clock is still ok */13711371+ if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {13721372+ intel_dp_start_link_train(intel_dp);13731373+ cr_tries++;13741374+ continue;13751375+ }13761376+13861377 if (intel_channel_eq_ok(intel_dp)) {13871378 channel_eq = true;13881379 break;13891380 }1390138113911391- /* Try 5 times */13921392- if (tries > 5)13931393- break;13821382+ /* Try 5 times, then try clock recovery if that fails */13831383+ if (tries > 5) {13841384+ intel_dp_link_down(intel_dp);13851385+ intel_dp_start_link_train(intel_dp);13861386+ tries = 0;13871387+ cr_tries++;13881388+ continue;13891389+ }1394139013951391 /* Compute new intel_dp->train_set as requested by target */13961392 intel_get_adjust_train(intel_dp);
···10241024 if (!intel_sdvo_set_target_input(intel_sdvo))10251025 return;1026102610271027- if (intel_sdvo->has_hdmi_monitor &&10281028- !intel_sdvo_set_avi_infoframe(intel_sdvo))10291029- return;10271027+ if (intel_sdvo->has_hdmi_monitor) {10281028+ intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);10291029+ intel_sdvo_set_colorimetry(intel_sdvo,10301030+ SDVO_COLORIMETRY_RGB256);10311031+ intel_sdvo_set_avi_infoframe(intel_sdvo);10321032+ } else10331033+ intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_DVI);1030103410311035 if (intel_sdvo->is_tv &&10321036 !intel_sdvo_set_tv_format(intel_sdvo))···14011397 return connector_status_disconnected;1402139814031399 intel_sdvo->attached_output = response;14001400+14011401+ intel_sdvo->has_hdmi_monitor = false;14021402+ intel_sdvo->has_hdmi_audio = false;1404140314051404 if ((intel_sdvo_connector->output_flag & response) == 0)14061405 ret = connector_status_disconnected;···19291922static bool19301923intel_sdvo_is_hdmi_connector(struct intel_sdvo *intel_sdvo, int device)19311924{19321932- int is_hdmi;19331933-19341934- if (!intel_sdvo_check_supp_encode(intel_sdvo))19351935- return false;19361936-19371937- if (!intel_sdvo_set_target_output(intel_sdvo,19381938- device == 0 ? SDVO_OUTPUT_TMDS0 : SDVO_OUTPUT_TMDS1))19391939- return false;19401940-19411941- is_hdmi = 0;19421942- if (!intel_sdvo_get_value(intel_sdvo, SDVO_CMD_GET_ENCODE, &is_hdmi, 1))19431943- return false;19441944-19451945- return !!is_hdmi;19251925+ return intel_sdvo_check_supp_encode(intel_sdvo);19461926}1947192719481928static u8···20312037 connector->connector_type = DRM_MODE_CONNECTOR_DVID;2032203820332039 if (intel_sdvo_is_hdmi_connector(intel_sdvo, device)) {20342034- /* enable hdmi encoding mode if supported */20352035- intel_sdvo_set_encode(intel_sdvo, SDVO_ENCODE_HDMI);20362036- intel_sdvo_set_colorimetry(intel_sdvo,20372037- SDVO_COLORIMETRY_RGB256);20382040 connector->connector_type = DRM_MODE_CONNECTOR_HDMIA;20392039-20402041 intel_sdvo->is_hdmi = true;20412042 }20422043 intel_sdvo->base.clone_mask = ((1 << INTEL_SDVO_NON_TV_CLONE_BIT) |
+1
drivers/net/Kconfig
···29632963config XEN_NETDEV_FRONTEND29642964 tristate "Xen network device frontend driver"29652965 depends on XEN29662966+ select XEN_XENBUS_FRONTEND29662967 default y29672968 help29682969 The network device frontend driver allows the kernel to
+1
drivers/pci/Kconfig
···4545 depends on PCI && X86 && XEN4646 select HOTPLUG4747 select PCI_XEN4848+ select XEN_XENBUS_FRONTEND4849 default y4950 help5051 The PCI device frontend driver allows the kernel to import arbitrary
+11
drivers/xen/Kconfig
···2929 firing.3030 If in doubt, say yes.31313232+config XEN_BACKEND3333+ bool "Backend driver support"3434+ depends on XEN_DOM03535+ default y3636+ help3737+ Support for backend device drivers that provide I/O services3838+ to other virtual machines.3939+3240config XENFS3341 tristate "Xen filesystem"3442 default y···6961 hypervisor environment. When running native or in another7062 virtual environment, /sys/hypervisor will still be present,7163 but will have no xen contents.6464+6565+config XEN_XENBUS_FRONTEND6666+ tristate72677368config XEN_PLATFORM_PCI7469 tristate "xen platform pci device driver"
···11+/******************************************************************************22+ * Talks to Xen Store to figure out what devices we have (backend half).33+ *44+ * Copyright (C) 2005 Rusty Russell, IBM Corporation55+ * Copyright (C) 2005 Mike Wray, Hewlett-Packard66+ * Copyright (C) 2005, 2006 XenSource Ltd77+ * Copyright (C) 2007 Solarflare Communications, Inc.88+ *99+ * This program is free software; you can redistribute it and/or1010+ * modify it under the terms of the GNU General Public License version 21111+ * as published by the Free Software Foundation; or, when distributed1212+ * separately from the Linux kernel or incorporated into other1313+ * software packages, subject to the following license:1414+ *1515+ * Permission is hereby granted, free of charge, to any person obtaining a copy1616+ * of this source file (the "Software"), to deal in the Software without1717+ * restriction, including without limitation the rights to use, copy, modify,1818+ * merge, publish, distribute, sublicense, and/or sell copies of the Software,1919+ * and to permit persons to whom the Software is furnished to do so, subject to2020+ * the following conditions:2121+ *2222+ * The above copyright notice and this permission notice shall be included in2323+ * all copies or substantial portions of the Software.2424+ *2525+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR2626+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,2727+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE2828+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER2929+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING3030+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS3131+ * IN THE SOFTWARE.3232+ */3333+3434+#define DPRINTK(fmt, args...) \3535+ pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \3636+ __func__, __LINE__, ##args)3737+3838+#include <linux/kernel.h>3939+#include <linux/err.h>4040+#include <linux/string.h>4141+#include <linux/ctype.h>4242+#include <linux/fcntl.h>4343+#include <linux/mm.h>4444+#include <linux/notifier.h>4545+4646+#include <asm/page.h>4747+#include <asm/pgtable.h>4848+#include <asm/xen/hypervisor.h>4949+#include <asm/hypervisor.h>5050+#include <xen/xenbus.h>5151+#include <xen/features.h>5252+5353+#include "xenbus_comms.h"5454+#include "xenbus_probe.h"5555+5656+/* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */5757+static int backend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename)5858+{5959+ int domid, err;6060+ const char *devid, *type, *frontend;6161+ unsigned int typelen;6262+6363+ type = strchr(nodename, '/');6464+ if (!type)6565+ return -EINVAL;6666+ type++;6767+ typelen = strcspn(type, "/");6868+ if (!typelen || type[typelen] != '/')6969+ return -EINVAL;7070+7171+ devid = strrchr(nodename, '/') + 1;7272+7373+ err = xenbus_gather(XBT_NIL, nodename, "frontend-id", "%i", &domid,7474+ "frontend", NULL, &frontend,7575+ NULL);7676+ if (err)7777+ return err;7878+ if (strlen(frontend) == 0)7979+ err = -ERANGE;8080+ if (!err && !xenbus_exists(XBT_NIL, frontend, ""))8181+ err = -ENOENT;8282+ kfree(frontend);8383+8484+ if (err)8585+ return err;8686+8787+ if (snprintf(bus_id, XEN_BUS_ID_SIZE, "%.*s-%i-%s",8888+ typelen, type, domid, devid) >= XEN_BUS_ID_SIZE)8989+ return -ENOSPC;9090+ return 0;9191+}9292+9393+static int xenbus_uevent_backend(struct device *dev,9494+ struct kobj_uevent_env *env)9595+{9696+ struct xenbus_device *xdev;9797+ struct xenbus_driver *drv;9898+ struct xen_bus_type *bus;9999+100100+ DPRINTK("");101101+102102+ if (dev == NULL)103103+ return -ENODEV;104104+105105+ xdev = to_xenbus_device(dev);106106+ bus = container_of(xdev->dev.bus, struct xen_bus_type, bus);107107+ if (xdev == NULL)108108+ return -ENODEV;109109+110110+ /* stuff we want to pass to /sbin/hotplug */111111+ if (add_uevent_var(env, "XENBUS_TYPE=%s", xdev->devicetype))112112+ return -ENOMEM;113113+114114+ if (add_uevent_var(env, "XENBUS_PATH=%s", xdev->nodename))115115+ return -ENOMEM;116116+117117+ if (add_uevent_var(env, "XENBUS_BASE_PATH=%s", bus->root))118118+ return -ENOMEM;119119+120120+ if (dev->driver) {121121+ drv = to_xenbus_driver(dev->driver);122122+ if (drv && drv->uevent)123123+ return drv->uevent(xdev, env);124124+ }125125+126126+ return 0;127127+}128128+129129+/* backend/<typename>/<frontend-uuid>/<name> */130130+static int xenbus_probe_backend_unit(struct xen_bus_type *bus,131131+ const char *dir,132132+ const char *type,133133+ const char *name)134134+{135135+ char *nodename;136136+ int err;137137+138138+ nodename = kasprintf(GFP_KERNEL, "%s/%s", dir, name);139139+ if (!nodename)140140+ return -ENOMEM;141141+142142+ DPRINTK("%s\n", nodename);143143+144144+ err = xenbus_probe_node(bus, type, nodename);145145+ kfree(nodename);146146+ return err;147147+}148148+149149+/* backend/<typename>/<frontend-domid> */150150+static int xenbus_probe_backend(struct xen_bus_type *bus, const char *type,151151+ const char *domid)152152+{153153+ char *nodename;154154+ int err = 0;155155+ char **dir;156156+ unsigned int i, dir_n = 0;157157+158158+ DPRINTK("");159159+160160+ nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", bus->root, type, domid);161161+ if (!nodename)162162+ return -ENOMEM;163163+164164+ dir = xenbus_directory(XBT_NIL, nodename, "", &dir_n);165165+ if (IS_ERR(dir)) {166166+ kfree(nodename);167167+ return PTR_ERR(dir);168168+ }169169+170170+ for (i = 0; i < dir_n; i++) {171171+ err = xenbus_probe_backend_unit(bus, nodename, type, dir[i]);172172+ if (err)173173+ break;174174+ }175175+ kfree(dir);176176+ kfree(nodename);177177+ return err;178178+}179179+180180+static void frontend_changed(struct xenbus_watch *watch,181181+ const char **vec, unsigned int len)182182+{183183+ xenbus_otherend_changed(watch, vec, len, 0);184184+}185185+186186+static struct device_attribute xenbus_backend_dev_attrs[] = {187187+ __ATTR_NULL188188+};189189+190190+static struct xen_bus_type xenbus_backend = {191191+ .root = "backend",192192+ .levels = 3, /* backend/type/<frontend>/<id> */193193+ .get_bus_id = backend_bus_id,194194+ .probe = xenbus_probe_backend,195195+ .otherend_changed = frontend_changed,196196+ .bus = {197197+ .name = "xen-backend",198198+ .match = xenbus_match,199199+ .uevent = xenbus_uevent_backend,200200+ .probe = xenbus_dev_probe,201201+ .remove = xenbus_dev_remove,202202+ .shutdown = xenbus_dev_shutdown,203203+ .dev_attrs = xenbus_backend_dev_attrs,204204+ },205205+};206206+207207+static void backend_changed(struct xenbus_watch *watch,208208+ const char **vec, unsigned int len)209209+{210210+ DPRINTK("");211211+212212+ xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_backend);213213+}214214+215215+static struct xenbus_watch be_watch = {216216+ .node = "backend",217217+ .callback = backend_changed,218218+};219219+220220+static int read_frontend_details(struct xenbus_device *xendev)221221+{222222+ return xenbus_read_otherend_details(xendev, "frontend-id", "frontend");223223+}224224+225225+int xenbus_dev_is_online(struct xenbus_device *dev)226226+{227227+ int rc, val;228228+229229+ rc = xenbus_scanf(XBT_NIL, dev->nodename, "online", "%d", &val);230230+ if (rc != 1)231231+ val = 0; /* no online node present */232232+233233+ return val;234234+}235235+EXPORT_SYMBOL_GPL(xenbus_dev_is_online);236236+237237+int __xenbus_register_backend(struct xenbus_driver *drv,238238+ struct module *owner, const char *mod_name)239239+{240240+ drv->read_otherend_details = read_frontend_details;241241+242242+ return xenbus_register_driver_common(drv, &xenbus_backend,243243+ owner, mod_name);244244+}245245+EXPORT_SYMBOL_GPL(__xenbus_register_backend);246246+247247+static int backend_probe_and_watch(struct notifier_block *notifier,248248+ unsigned long event,249249+ void *data)250250+{251251+ /* Enumerate devices in xenstore and watch for changes. */252252+ xenbus_probe_devices(&xenbus_backend);253253+ register_xenbus_watch(&be_watch);254254+255255+ return NOTIFY_DONE;256256+}257257+258258+static int __init xenbus_probe_backend_init(void)259259+{260260+ static struct notifier_block xenstore_notifier = {261261+ .notifier_call = backend_probe_and_watch262262+ };263263+ int err;264264+265265+ DPRINTK("");266266+267267+ /* Register ourselves with the kernel bus subsystem */268268+ err = bus_register(&xenbus_backend.bus);269269+ if (err)270270+ return err;271271+272272+ register_xenstore_notifier(&xenstore_notifier);273273+274274+ return 0;275275+}276276+subsys_initcall(xenbus_probe_backend_init);
+294
drivers/xen/xenbus/xenbus_probe_frontend.c
···11+#define DPRINTK(fmt, args...) \22+ pr_debug("xenbus_probe (%s:%d) " fmt ".\n", \33+ __func__, __LINE__, ##args)44+55+#include <linux/kernel.h>66+#include <linux/err.h>77+#include <linux/string.h>88+#include <linux/ctype.h>99+#include <linux/fcntl.h>1010+#include <linux/mm.h>1111+#include <linux/proc_fs.h>1212+#include <linux/notifier.h>1313+#include <linux/kthread.h>1414+#include <linux/mutex.h>1515+#include <linux/io.h>1616+1717+#include <asm/page.h>1818+#include <asm/pgtable.h>1919+#include <asm/xen/hypervisor.h>2020+#include <xen/xenbus.h>2121+#include <xen/events.h>2222+#include <xen/page.h>2323+2424+#include <xen/platform_pci.h>2525+2626+#include "xenbus_comms.h"2727+#include "xenbus_probe.h"2828+2929+3030+/* device/<type>/<id> => <type>-<id> */3131+static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename)3232+{3333+ nodename = strchr(nodename, '/');3434+ if (!nodename || strlen(nodename + 1) >= XEN_BUS_ID_SIZE) {3535+ printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename);3636+ return -EINVAL;3737+ }3838+3939+ strlcpy(bus_id, nodename + 1, XEN_BUS_ID_SIZE);4040+ if (!strchr(bus_id, '/')) {4141+ printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id);4242+ return -EINVAL;4343+ }4444+ *strchr(bus_id, '/') = '-';4545+ return 0;4646+}4747+4848+/* device/<typename>/<name> */4949+static int xenbus_probe_frontend(struct xen_bus_type *bus, const char *type,5050+ const char *name)5151+{5252+ char *nodename;5353+ int err;5454+5555+ nodename = kasprintf(GFP_KERNEL, "%s/%s/%s", bus->root, type, name);5656+ if (!nodename)5757+ return -ENOMEM;5858+5959+ DPRINTK("%s", nodename);6060+6161+ err = xenbus_probe_node(bus, type, nodename);6262+ kfree(nodename);6363+ return err;6464+}6565+6666+static int xenbus_uevent_frontend(struct device *_dev,6767+ struct kobj_uevent_env *env)6868+{6969+ struct xenbus_device *dev = to_xenbus_device(_dev);7070+7171+ if (add_uevent_var(env, "MODALIAS=xen:%s", dev->devicetype))7272+ return -ENOMEM;7373+7474+ return 0;7575+}7676+7777+7878+static void backend_changed(struct xenbus_watch *watch,7979+ const char **vec, unsigned int len)8080+{8181+ xenbus_otherend_changed(watch, vec, len, 1);8282+}8383+8484+static struct device_attribute xenbus_frontend_dev_attrs[] = {8585+ __ATTR_NULL8686+};8787+8888+static struct xen_bus_type xenbus_frontend = {8989+ .root = "device",9090+ .levels = 2, /* device/type/<id> */9191+ .get_bus_id = frontend_bus_id,9292+ .probe = xenbus_probe_frontend,9393+ .otherend_changed = backend_changed,9494+ .bus = {9595+ .name = "xen",9696+ .match = xenbus_match,9797+ .uevent = xenbus_uevent_frontend,9898+ .probe = xenbus_dev_probe,9999+ .remove = xenbus_dev_remove,100100+ .shutdown = xenbus_dev_shutdown,101101+ .dev_attrs = xenbus_frontend_dev_attrs,102102+103103+ .suspend = xenbus_dev_suspend,104104+ .resume = xenbus_dev_resume,105105+ },106106+};107107+108108+static void frontend_changed(struct xenbus_watch *watch,109109+ const char **vec, unsigned int len)110110+{111111+ DPRINTK("");112112+113113+ xenbus_dev_changed(vec[XS_WATCH_PATH], &xenbus_frontend);114114+}115115+116116+117117+/* We watch for devices appearing and vanishing. */118118+static struct xenbus_watch fe_watch = {119119+ .node = "device",120120+ .callback = frontend_changed,121121+};122122+123123+static int read_backend_details(struct xenbus_device *xendev)124124+{125125+ return xenbus_read_otherend_details(xendev, "backend-id", "backend");126126+}127127+128128+static int is_device_connecting(struct device *dev, void *data)129129+{130130+ struct xenbus_device *xendev = to_xenbus_device(dev);131131+ struct device_driver *drv = data;132132+ struct xenbus_driver *xendrv;133133+134134+ /*135135+ * A device with no driver will never connect. We care only about136136+ * devices which should currently be in the process of connecting.137137+ */138138+ if (!dev->driver)139139+ return 0;140140+141141+ /* Is this search limited to a particular driver? */142142+ if (drv && (dev->driver != drv))143143+ return 0;144144+145145+ xendrv = to_xenbus_driver(dev->driver);146146+ return (xendev->state < XenbusStateConnected ||147147+ (xendev->state == XenbusStateConnected &&148148+ xendrv->is_ready && !xendrv->is_ready(xendev)));149149+}150150+151151+static int exists_connecting_device(struct device_driver *drv)152152+{153153+ return bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,154154+ is_device_connecting);155155+}156156+157157+static int print_device_status(struct device *dev, void *data)158158+{159159+ struct xenbus_device *xendev = to_xenbus_device(dev);160160+ struct device_driver *drv = data;161161+162162+ /* Is this operation limited to a particular driver? */163163+ if (drv && (dev->driver != drv))164164+ return 0;165165+166166+ if (!dev->driver) {167167+ /* Information only: is this too noisy? */168168+ printk(KERN_INFO "XENBUS: Device with no driver: %s\n",169169+ xendev->nodename);170170+ } else if (xendev->state < XenbusStateConnected) {171171+ enum xenbus_state rstate = XenbusStateUnknown;172172+ if (xendev->otherend)173173+ rstate = xenbus_read_driver_state(xendev->otherend);174174+ printk(KERN_WARNING "XENBUS: Timeout connecting "175175+ "to device: %s (local state %d, remote state %d)\n",176176+ xendev->nodename, xendev->state, rstate);177177+ }178178+179179+ return 0;180180+}181181+182182+/* We only wait for device setup after most initcalls have run. */183183+static int ready_to_wait_for_devices;184184+185185+/*186186+ * On a 5-minute timeout, wait for all devices currently configured. We need187187+ * to do this to guarantee that the filesystems and / or network devices188188+ * needed for boot are available, before we can allow the boot to proceed.189189+ *190190+ * This needs to be on a late_initcall, to happen after the frontend device191191+ * drivers have been initialised, but before the root fs is mounted.192192+ *193193+ * A possible improvement here would be to have the tools add a per-device194194+ * flag to the store entry, indicating whether it is needed at boot time.195195+ * This would allow people who knew what they were doing to accelerate their196196+ * boot slightly, but of course needs tools or manual intervention to set up197197+ * those flags correctly.198198+ */199199+static void wait_for_devices(struct xenbus_driver *xendrv)200200+{201201+ unsigned long start = jiffies;202202+ struct device_driver *drv = xendrv ? &xendrv->driver : NULL;203203+ unsigned int seconds_waited = 0;204204+205205+ if (!ready_to_wait_for_devices || !xen_domain())206206+ return;207207+208208+ while (exists_connecting_device(drv)) {209209+ if (time_after(jiffies, start + (seconds_waited+5)*HZ)) {210210+ if (!seconds_waited)211211+ printk(KERN_WARNING "XENBUS: Waiting for "212212+ "devices to initialise: ");213213+ seconds_waited += 5;214214+ printk("%us...", 300 - seconds_waited);215215+ if (seconds_waited == 300)216216+ break;217217+ }218218+219219+ schedule_timeout_interruptible(HZ/10);220220+ }221221+222222+ if (seconds_waited)223223+ printk("\n");224224+225225+ bus_for_each_dev(&xenbus_frontend.bus, NULL, drv,226226+ print_device_status);227227+}228228+229229+int __xenbus_register_frontend(struct xenbus_driver *drv,230230+ struct module *owner, const char *mod_name)231231+{232232+ int ret;233233+234234+ drv->read_otherend_details = read_backend_details;235235+236236+ ret = xenbus_register_driver_common(drv, &xenbus_frontend,237237+ owner, mod_name);238238+ if (ret)239239+ return ret;240240+241241+ /* If this driver is loaded as a module wait for devices to attach. */242242+ wait_for_devices(drv);243243+244244+ return 0;245245+}246246+EXPORT_SYMBOL_GPL(__xenbus_register_frontend);247247+248248+static int frontend_probe_and_watch(struct notifier_block *notifier,249249+ unsigned long event,250250+ void *data)251251+{252252+ /* Enumerate devices in xenstore and watch for changes. */253253+ xenbus_probe_devices(&xenbus_frontend);254254+ register_xenbus_watch(&fe_watch);255255+256256+ return NOTIFY_DONE;257257+}258258+259259+260260+static int __init xenbus_probe_frontend_init(void)261261+{262262+ static struct notifier_block xenstore_notifier = {263263+ .notifier_call = frontend_probe_and_watch264264+ };265265+ int err;266266+267267+ DPRINTK("");268268+269269+ /* Register ourselves with the kernel bus subsystem */270270+ err = bus_register(&xenbus_frontend.bus);271271+ if (err)272272+ return err;273273+274274+ register_xenstore_notifier(&xenstore_notifier);275275+276276+ return 0;277277+}278278+subsys_initcall(xenbus_probe_frontend_init);279279+280280+#ifndef MODULE281281+static int __init boot_wait_for_devices(void)282282+{283283+ if (xen_hvm_domain() && !xen_platform_pci_unplug)284284+ return -ENODEV;285285+286286+ ready_to_wait_for_devices = 1;287287+ wait_for_devices(NULL);288288+ return 0;289289+}290290+291291+late_initcall(boot_wait_for_devices);292292+#endif293293+294294+MODULE_LICENSE("GPL");
···11/*22 * file.c - NTFS kernel file operations. Part of the Linux-NTFS project.33 *44- * Copyright (c) 2001-2007 Anton Altaparmakov44+ * Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc.55 *66 * This program/include file is free software; you can redistribute it and/or77 * modify it under the terms of the GNU General Public License as published···13801380 * pages (out to offset + bytes), to emulate ntfs_copy_from_user()'s13811381 * single-segment behaviour.13821382 *13831383- * We call the same helper (__ntfs_copy_from_user_iovec_inatomic()) both13841384- * when atomic and when not atomic. This is ok because13851385- * __ntfs_copy_from_user_iovec_inatomic() calls __copy_from_user_inatomic()13861386- * and it is ok to call this when non-atomic.13871387- * Infact, the only difference between __copy_from_user_inatomic() and13831383+ * We call the same helper (__ntfs_copy_from_user_iovec_inatomic()) both when13841384+ * atomic and when not atomic. This is ok because it calls13851385+ * __copy_from_user_inatomic() and it is ok to call this when non-atomic. In13861386+ * fact, the only difference between __copy_from_user_inatomic() and13881387 * __copy_from_user() is that the latter calls might_sleep() and the former13891389- * should not zero the tail of the buffer on error. And on many13901390- * architectures __copy_from_user_inatomic() is just defined to13911391- * __copy_from_user() so it makes no difference at all on those architectures.13881388+ * should not zero the tail of the buffer on error. And on many architectures13891389+ * __copy_from_user_inatomic() is just defined to __copy_from_user() so it13901390+ * makes no difference at all on those architectures.13921391 */13931392static inline size_t ntfs_copy_from_user_iovec(struct page **pages,13941393 unsigned nr_pages, unsigned ofs, const struct iovec **iov,···14081409 if (unlikely(copied != len)) {14091410 /* Do it the slow way. */14101411 addr = kmap(*pages);14111411- copied = __ntfs_copy_from_user_iovec_inatomic(addr + ofs,14121412- *iov, *iov_ofs, len);14131413- /*14141414- * Zero the rest of the target like __copy_from_user().14151415- */14161416- memset(addr + ofs + copied, 0, len - copied);14171417- kunmap(*pages);14121412+ copied = __ntfs_copy_from_user_iovec_inatomic(addr +14131413+ ofs, *iov, *iov_ofs, len);14181414 if (unlikely(copied != len))14191415 goto err_out;14161416+ kunmap(*pages);14201417 }14211418 total += len;14191419+ ntfs_set_next_iovec(iov, iov_ofs, len);14221420 bytes -= len;14231421 if (!bytes)14241422 break;14251425- ntfs_set_next_iovec(iov, iov_ofs, len);14261423 ofs = 0;14271424 } while (++pages < last_page);14281425out:14291426 return total;14301427err_out:14311431- total += copied;14281428+ BUG_ON(copied > len);14321429 /* Zero the rest of the target like __copy_from_user(). */14301430+ memset(addr + ofs + copied, 0, len - copied);14311431+ kunmap(*pages);14321432+ total += copied;14331433+ ntfs_set_next_iovec(iov, iov_ofs, copied);14331434 while (++pages < last_page) {14341435 bytes -= len;14351436 if (!bytes)
+3-3
fs/ntfs/super.c
···11/*22 * super.c - NTFS kernel super block handling. Part of the Linux-NTFS project.33 *44- * Copyright (c) 2001-2007 Anton Altaparmakov44+ * Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc.55 * Copyright (c) 2001,2002 Richard Russon66 *77 * This program/include file is free software; you can redistribute it and/or···31933193 ntfs_sysctl(0);31943194}3195319531963196-MODULE_AUTHOR("Anton Altaparmakov <aia21@cantab.net>");31973197-MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2007 Anton Altaparmakov");31963196+MODULE_AUTHOR("Anton Altaparmakov <anton@tuxera.com>");31973197+MODULE_DESCRIPTION("NTFS 1.2/3.x driver - Copyright (c) 2001-2011 Anton Altaparmakov and Tuxera Inc.");31983198MODULE_VERSION(NTFS_VERSION);31993199MODULE_LICENSE("GPL");32003200#ifdef DEBUG
+1-1
include/xen/xenbus.h
···9494 int (*remove)(struct xenbus_device *dev);9595 int (*suspend)(struct xenbus_device *dev, pm_message_t state);9696 int (*resume)(struct xenbus_device *dev);9797- int (*uevent)(struct xenbus_device *, char **, int, char *, int);9797+ int (*uevent)(struct xenbus_device *, struct kobj_uevent_env *);9898 struct device_driver driver;9999 int (*read_otherend_details)(struct xenbus_device *dev);100100 int (*is_ready)(struct xenbus_device *dev);
···11+.TH TURBOSTAT 822+.SH NAME33+turbostat \- Report processor frequency and idle statistics44+.SH SYNOPSIS55+.ft B66+.B turbostat77+.RB [ "\-v" ]88+.RB [ "\-M MSR#" ]99+.RB command1010+.br1111+.B turbostat1212+.RB [ "\-v" ]1313+.RB [ "\-M MSR#" ]1414+.RB [ "\-i interval_sec" ]1515+.SH DESCRIPTION1616+\fBturbostat \fP reports processor topology, frequency1717+and idle power state statistics on modern X86 processors.1818+Either \fBcommand\fP is forked and statistics are printed1919+upon its completion, or statistics are printed periodically.2020+2121+\fBturbostat \fP2222+requires that the processor2323+supports an "invariant" TSC, plus the APERF and MPERF MSRs.2424+\fBturbostat \fP will report idle cpu power state residency2525+on processors that additionally support C-state residency counters.2626+2727+.SS Options2828+The \fB-v\fP option increases verbosity.2929+.PP3030+The \fB-M MSR#\fP option dumps the specified MSR,3131+in addition to the usual frequency and idle statistics.3232+.PP3333+The \fB-i interval_sec\fP option prints statistics every \fiinterval_sec\fP seconds.3434+The default is 5 seconds.3535+.PP3636+The \fBcommand\fP parameter forks \fBcommand\fP and upon its exit,3737+displays the statistics gathered since it was forked.3838+.PP3939+.SH FIELD DESCRIPTIONS4040+.nf4141+\fBpkg\fP processor package number.4242+\fBcore\fP processor core number.4343+\fBCPU\fP Linux CPU (logical processor) number.4444+\fB%c0\fP percent of the interval that the CPU retired instructions.4545+\fBGHz\fP average clock rate while the CPU was in c0 state.4646+\fBTSC\fP average GHz that the TSC ran during the entire interval.4747+\fB%c1, %c3, %c6\fP show the percentage residency in hardware core idle states.4848+\fB%pc3, %pc6\fP percentage residency in hardware package idle states.4949+.fi5050+.PP5151+.SH EXAMPLE5252+Without any parameters, turbostat prints out counters ever 5 seconds.5353+(override interval with "-i sec" option, or specify a command5454+for turbostat to fork).5555+5656+The first row of statistics reflect the average for the entire system.5757+Subsequent rows show per-CPU statistics.5858+5959+.nf6060+[root@x980]# ./turbostat6161+core CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc66262+ 0.04 1.62 3.38 0.11 0.00 99.85 0.00 95.076363+ 0 0 0.04 1.62 3.38 0.06 0.00 99.90 0.00 95.076464+ 0 6 0.02 1.62 3.38 0.08 0.00 99.90 0.00 95.076565+ 1 2 0.10 1.62 3.38 0.29 0.00 99.61 0.00 95.076666+ 1 8 0.11 1.62 3.38 0.28 0.00 99.61 0.00 95.076767+ 2 4 0.01 1.62 3.38 0.01 0.00 99.98 0.00 95.076868+ 2 10 0.01 1.61 3.38 0.02 0.00 99.98 0.00 95.076969+ 8 1 0.07 1.62 3.38 0.15 0.00 99.78 0.00 95.077070+ 8 7 0.03 1.62 3.38 0.19 0.00 99.78 0.00 95.077171+ 9 3 0.01 1.62 3.38 0.02 0.00 99.98 0.00 95.077272+ 9 9 0.01 1.62 3.38 0.02 0.00 99.98 0.00 95.077373+ 10 5 0.01 1.62 3.38 0.13 0.00 99.86 0.00 95.077474+ 10 11 0.08 1.62 3.38 0.05 0.00 99.86 0.00 95.077575+.fi7676+.SH VERBOSE EXAMPLE7777+The "-v" option adds verbosity to the output:7878+7979+.nf8080+GenuineIntel 11 CPUID levels; family:model:stepping 0x6:2c:2 (6:44:2)8181+12 * 133 = 1600 MHz max efficiency8282+25 * 133 = 3333 MHz TSC frequency8383+26 * 133 = 3467 MHz max turbo 4 active cores8484+26 * 133 = 3467 MHz max turbo 3 active cores8585+27 * 133 = 3600 MHz max turbo 2 active cores8686+27 * 133 = 3600 MHz max turbo 1 active cores8787+8888+.fi8989+The \fBmax efficiency\fP frequency, a.k.a. Low Frequency Mode, is the frequency9090+available at the minimum package voltage. The \fBTSC frequency\fP is the nominal9191+maximum frequency of the processor if turbo-mode were not available. This frequency9292+should be sustainable on all CPUs indefinitely, given nominal power and cooling.9393+The remaining rows show what maximum turbo frequency is possible9494+depending on the number of idle cores. Note that this information is9595+not available on all processors.9696+.SH FORK EXAMPLE9797+If turbostat is invoked with a command, it will fork that command9898+and output the statistics gathered when the command exits.9999+eg. Here a cycle soaker is run on 1 CPU (see %c0) for a few seconds100100+until ^C while the other CPUs are mostly idle:101101+102102+.nf103103+[root@x980 lenb]# ./turbostat cat /dev/zero > /dev/null104104+105105+^Ccore CPU %c0 GHz TSC %c1 %c3 %c6 %pc3 %pc6106106+ 8.49 3.63 3.38 16.23 0.66 74.63 0.00 0.00107107+ 0 0 1.22 3.62 3.38 32.18 0.00 66.60 0.00 0.00108108+ 0 6 0.40 3.61 3.38 33.00 0.00 66.60 0.00 0.00109109+ 1 2 0.11 3.14 3.38 0.19 3.95 95.75 0.00 0.00110110+ 1 8 0.05 2.88 3.38 0.25 3.95 95.75 0.00 0.00111111+ 2 4 0.00 3.13 3.38 0.02 0.00 99.98 0.00 0.00112112+ 2 10 0.00 3.09 3.38 0.02 0.00 99.98 0.00 0.00113113+ 8 1 0.04 3.50 3.38 14.43 0.00 85.54 0.00 0.00114114+ 8 7 0.03 2.98 3.38 14.43 0.00 85.54 0.00 0.00115115+ 9 3 0.00 3.16 3.38 100.00 0.00 0.00 0.00 0.00116116+ 9 9 99.93 3.63 3.38 0.06 0.00 0.00 0.00 0.00117117+ 10 5 0.01 2.82 3.38 0.08 0.00 99.91 0.00 0.00118118+ 10 11 0.02 3.36 3.38 0.06 0.00 99.91 0.00 0.00119119+6.950866 sec120120+121121+.fi122122+Above the cycle soaker drives cpu9 up 3.6 Ghz turbo limit123123+while the other processors are generally in various states of idle.124124+125125+Note that cpu3 is an HT sibling sharing core9126126+with cpu9, and thus it is unable to get to an idle state127127+deeper than c1 while cpu9 is busy.128128+129129+Note that turbostat reports average GHz of 3.61, while130130+the arithmetic average of the GHz column above is 3.24.131131+This is a weighted average, where the weight is %c0. ie. it is the total number of132132+un-halted cycles elapsed per time divided by the number of CPUs.133133+.SH NOTES134134+135135+.B "turbostat "136136+must be run as root.137137+138138+.B "turbostat "139139+reads hardware counters, but doesn't write them.140140+So it will not interfere with the OS or other programs, including141141+multiple invocations of itself.142142+143143+\fBturbostat \fP144144+may work poorly on Linux-2.6.20 through 2.6.29,145145+as \fBacpi-cpufreq \fPperiodically cleared the APERF and MPERF146146+in those kernels.147147+148148+The APERF, MPERF MSRs are defined to count non-halted cycles.149149+Although it is not guaranteed by the architecture, turbostat assumes150150+that they count at TSC rate, which is true on all processors tested to date.151151+152152+.SH REFERENCES153153+"Intel® Turbo Boost Technology154154+in Intel® Core™ Microarchitecture (Nehalem) Based Processors"155155+http://download.intel.com/design/processor/applnots/320354.pdf156156+157157+"Intel® 64 and IA-32 Architectures Software Developer's Manual158158+Volume 3B: System Programming Guide"159159+http://www.intel.com/products/processor/manuals/160160+161161+.SH FILES162162+.ta163163+.nf164164+/dev/cpu/*/msr165165+.fi166166+167167+.SH "SEE ALSO"168168+msr(4), vmstat(8)169169+.PP170170+.SH AUTHORS171171+.nf172172+Written by Len Brown <len.brown@intel.com>
+1048
tools/power/x86/turbostat/turbostat.c
···11+/*22+ * turbostat -- show CPU frequency and C-state residency33+ * on modern Intel turbo-capable processors.44+ *55+ * Copyright (c) 2010, Intel Corporation.66+ * Len Brown <len.brown@intel.com>77+ *88+ * This program is free software; you can redistribute it and/or modify it99+ * under the terms and conditions of the GNU General Public License,1010+ * version 2, as published by the Free Software Foundation.1111+ *1212+ * This program is distributed in the hope it will be useful, but WITHOUT1313+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1414+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1515+ * more details.1616+ *1717+ * You should have received a copy of the GNU General Public License along with1818+ * this program; if not, write to the Free Software Foundation, Inc.,1919+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.2020+ */2121+2222+#include <stdio.h>2323+#include <unistd.h>2424+#include <sys/types.h>2525+#include <sys/wait.h>2626+#include <sys/stat.h>2727+#include <sys/resource.h>2828+#include <fcntl.h>2929+#include <signal.h>3030+#include <sys/time.h>3131+#include <stdlib.h>3232+#include <dirent.h>3333+#include <string.h>3434+#include <ctype.h>3535+3636+#define MSR_TSC 0x103737+#define MSR_NEHALEM_PLATFORM_INFO 0xCE3838+#define MSR_NEHALEM_TURBO_RATIO_LIMIT 0x1AD3939+#define MSR_APERF 0xE84040+#define MSR_MPERF 0xE74141+#define MSR_PKG_C2_RESIDENCY 0x60D /* SNB only */4242+#define MSR_PKG_C3_RESIDENCY 0x3F84343+#define MSR_PKG_C6_RESIDENCY 0x3F94444+#define MSR_PKG_C7_RESIDENCY 0x3FA /* SNB only */4545+#define MSR_CORE_C3_RESIDENCY 0x3FC4646+#define MSR_CORE_C6_RESIDENCY 0x3FD4747+#define MSR_CORE_C7_RESIDENCY 0x3FE /* SNB only */4848+4949+char *proc_stat = "/proc/stat";5050+unsigned int interval_sec = 5; /* set with -i interval_sec */5151+unsigned int verbose; /* set with -v */5252+unsigned int skip_c0;5353+unsigned int skip_c1;5454+unsigned int do_nhm_cstates;5555+unsigned int do_snb_cstates;5656+unsigned int has_aperf;5757+unsigned int units = 1000000000; /* Ghz etc */5858+unsigned int genuine_intel;5959+unsigned int has_invariant_tsc;6060+unsigned int do_nehalem_platform_info;6161+unsigned int do_nehalem_turbo_ratio_limit;6262+unsigned int extra_msr_offset;6363+double bclk;6464+unsigned int show_pkg;6565+unsigned int show_core;6666+unsigned int show_cpu;6767+6868+int aperf_mperf_unstable;6969+int backwards_count;7070+char *progname;7171+int need_reinitialize;7272+7373+int num_cpus;7474+7575+typedef struct per_cpu_counters {7676+ unsigned long long tsc; /* per thread */7777+ unsigned long long aperf; /* per thread */7878+ unsigned long long mperf; /* per thread */7979+ unsigned long long c1; /* per thread (calculated) */8080+ unsigned long long c3; /* per core */8181+ unsigned long long c6; /* per core */8282+ unsigned long long c7; /* per core */8383+ unsigned long long pc2; /* per package */8484+ unsigned long long pc3; /* per package */8585+ unsigned long long pc6; /* per package */8686+ unsigned long long pc7; /* per package */8787+ unsigned long long extra_msr; /* per thread */8888+ int pkg;8989+ int core;9090+ int cpu;9191+ struct per_cpu_counters *next;9292+} PCC;9393+9494+PCC *pcc_even;9595+PCC *pcc_odd;9696+PCC *pcc_delta;9797+PCC *pcc_average;9898+struct timeval tv_even;9999+struct timeval tv_odd;100100+struct timeval tv_delta;101101+102102+unsigned long long get_msr(int cpu, off_t offset)103103+{104104+ ssize_t retval;105105+ unsigned long long msr;106106+ char pathname[32];107107+ int fd;108108+109109+ sprintf(pathname, "/dev/cpu/%d/msr", cpu);110110+ fd = open(pathname, O_RDONLY);111111+ if (fd < 0) {112112+ perror(pathname);113113+ need_reinitialize = 1;114114+ return 0;115115+ }116116+117117+ retval = pread(fd, &msr, sizeof msr, offset);118118+ if (retval != sizeof msr) {119119+ fprintf(stderr, "cpu%d pread(..., 0x%zx) = %jd\n",120120+ cpu, offset, retval);121121+ exit(-2);122122+ }123123+124124+ close(fd);125125+ return msr;126126+}127127+128128+void print_header()129129+{130130+ if (show_pkg)131131+ fprintf(stderr, "pkg ");132132+ if (show_core)133133+ fprintf(stderr, "core");134134+ if (show_cpu)135135+ fprintf(stderr, " CPU");136136+ if (do_nhm_cstates)137137+ fprintf(stderr, " %%c0 ");138138+ if (has_aperf)139139+ fprintf(stderr, " GHz");140140+ fprintf(stderr, " TSC");141141+ if (do_nhm_cstates)142142+ fprintf(stderr, " %%c1 ");143143+ if (do_nhm_cstates)144144+ fprintf(stderr, " %%c3 ");145145+ if (do_nhm_cstates)146146+ fprintf(stderr, " %%c6 ");147147+ if (do_snb_cstates)148148+ fprintf(stderr, " %%c7 ");149149+ if (do_snb_cstates)150150+ fprintf(stderr, " %%pc2 ");151151+ if (do_nhm_cstates)152152+ fprintf(stderr, " %%pc3 ");153153+ if (do_nhm_cstates)154154+ fprintf(stderr, " %%pc6 ");155155+ if (do_snb_cstates)156156+ fprintf(stderr, " %%pc7 ");157157+ if (extra_msr_offset)158158+ fprintf(stderr, " MSR 0x%x ", extra_msr_offset);159159+160160+ putc('\n', stderr);161161+}162162+163163+void dump_pcc(PCC *pcc)164164+{165165+ fprintf(stderr, "package: %d ", pcc->pkg);166166+ fprintf(stderr, "core:: %d ", pcc->core);167167+ fprintf(stderr, "CPU: %d ", pcc->cpu);168168+ fprintf(stderr, "TSC: %016llX\n", pcc->tsc);169169+ fprintf(stderr, "c3: %016llX\n", pcc->c3);170170+ fprintf(stderr, "c6: %016llX\n", pcc->c6);171171+ fprintf(stderr, "c7: %016llX\n", pcc->c7);172172+ fprintf(stderr, "aperf: %016llX\n", pcc->aperf);173173+ fprintf(stderr, "pc2: %016llX\n", pcc->pc2);174174+ fprintf(stderr, "pc3: %016llX\n", pcc->pc3);175175+ fprintf(stderr, "pc6: %016llX\n", pcc->pc6);176176+ fprintf(stderr, "pc7: %016llX\n", pcc->pc7);177177+ fprintf(stderr, "msr0x%x: %016llX\n", extra_msr_offset, pcc->extra_msr);178178+}179179+180180+void dump_list(PCC *pcc)181181+{182182+ printf("dump_list 0x%p\n", pcc);183183+184184+ for (; pcc; pcc = pcc->next)185185+ dump_pcc(pcc);186186+}187187+188188+void print_pcc(PCC *p)189189+{190190+ double interval_float;191191+192192+ interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;193193+194194+ /* topology columns, print blanks on 1st (average) line */195195+ if (p == pcc_average) {196196+ if (show_pkg)197197+ fprintf(stderr, " ");198198+ if (show_core)199199+ fprintf(stderr, " ");200200+ if (show_cpu)201201+ fprintf(stderr, " ");202202+ } else {203203+ if (show_pkg)204204+ fprintf(stderr, "%4d", p->pkg);205205+ if (show_core)206206+ fprintf(stderr, "%4d", p->core);207207+ if (show_cpu)208208+ fprintf(stderr, "%4d", p->cpu);209209+ }210210+211211+ /* %c0 */212212+ if (do_nhm_cstates) {213213+ if (!skip_c0)214214+ fprintf(stderr, "%7.2f", 100.0 * p->mperf/p->tsc);215215+ else216216+ fprintf(stderr, " ****");217217+ }218218+219219+ /* GHz */220220+ if (has_aperf) {221221+ if (!aperf_mperf_unstable) {222222+ fprintf(stderr, "%5.2f",223223+ 1.0 * p->tsc / units * p->aperf /224224+ p->mperf / interval_float);225225+ } else {226226+ if (p->aperf > p->tsc || p->mperf > p->tsc) {227227+ fprintf(stderr, " ****");228228+ } else {229229+ fprintf(stderr, "%4.1f*",230230+ 1.0 * p->tsc /231231+ units * p->aperf /232232+ p->mperf / interval_float);233233+ }234234+ }235235+ }236236+237237+ /* TSC */238238+ fprintf(stderr, "%5.2f", 1.0 * p->tsc/units/interval_float);239239+240240+ if (do_nhm_cstates) {241241+ if (!skip_c1)242242+ fprintf(stderr, "%7.2f", 100.0 * p->c1/p->tsc);243243+ else244244+ fprintf(stderr, " ****");245245+ }246246+ if (do_nhm_cstates)247247+ fprintf(stderr, "%7.2f", 100.0 * p->c3/p->tsc);248248+ if (do_nhm_cstates)249249+ fprintf(stderr, "%7.2f", 100.0 * p->c6/p->tsc);250250+ if (do_snb_cstates)251251+ fprintf(stderr, "%7.2f", 100.0 * p->c7/p->tsc);252252+ if (do_snb_cstates)253253+ fprintf(stderr, "%7.2f", 100.0 * p->pc2/p->tsc);254254+ if (do_nhm_cstates)255255+ fprintf(stderr, "%7.2f", 100.0 * p->pc3/p->tsc);256256+ if (do_nhm_cstates)257257+ fprintf(stderr, "%7.2f", 100.0 * p->pc6/p->tsc);258258+ if (do_snb_cstates)259259+ fprintf(stderr, "%7.2f", 100.0 * p->pc7/p->tsc);260260+ if (extra_msr_offset)261261+ fprintf(stderr, " 0x%016llx", p->extra_msr);262262+ putc('\n', stderr);263263+}264264+265265+void print_counters(PCC *cnt)266266+{267267+ PCC *pcc;268268+269269+ print_header();270270+271271+ if (num_cpus > 1)272272+ print_pcc(pcc_average);273273+274274+ for (pcc = cnt; pcc != NULL; pcc = pcc->next)275275+ print_pcc(pcc);276276+277277+}278278+279279+#define SUBTRACT_COUNTER(after, before, delta) (delta = (after - before), (before > after))280280+281281+282282+int compute_delta(PCC *after, PCC *before, PCC *delta)283283+{284284+ int errors = 0;285285+ int perf_err = 0;286286+287287+ skip_c0 = skip_c1 = 0;288288+289289+ for ( ; after && before && delta;290290+ after = after->next, before = before->next, delta = delta->next) {291291+ if (before->cpu != after->cpu) {292292+ printf("cpu configuration changed: %d != %d\n",293293+ before->cpu, after->cpu);294294+ return -1;295295+ }296296+297297+ if (SUBTRACT_COUNTER(after->tsc, before->tsc, delta->tsc)) {298298+ fprintf(stderr, "cpu%d TSC went backwards %llX to %llX\n",299299+ before->cpu, before->tsc, after->tsc);300300+ errors++;301301+ }302302+ /* check for TSC < 1 Mcycles over interval */303303+ if (delta->tsc < (1000 * 1000)) {304304+ fprintf(stderr, "Insanely slow TSC rate,"305305+ " TSC stops in idle?\n");306306+ fprintf(stderr, "You can disable all c-states"307307+ " by booting with \"idle=poll\"\n");308308+ fprintf(stderr, "or just the deep ones with"309309+ " \"processor.max_cstate=1\"\n");310310+ exit(-3);311311+ }312312+ if (SUBTRACT_COUNTER(after->c3, before->c3, delta->c3)) {313313+ fprintf(stderr, "cpu%d c3 counter went backwards %llX to %llX\n",314314+ before->cpu, before->c3, after->c3);315315+ errors++;316316+ }317317+ if (SUBTRACT_COUNTER(after->c6, before->c6, delta->c6)) {318318+ fprintf(stderr, "cpu%d c6 counter went backwards %llX to %llX\n",319319+ before->cpu, before->c6, after->c6);320320+ errors++;321321+ }322322+ if (SUBTRACT_COUNTER(after->c7, before->c7, delta->c7)) {323323+ fprintf(stderr, "cpu%d c7 counter went backwards %llX to %llX\n",324324+ before->cpu, before->c7, after->c7);325325+ errors++;326326+ }327327+ if (SUBTRACT_COUNTER(after->pc2, before->pc2, delta->pc2)) {328328+ fprintf(stderr, "cpu%d pc2 counter went backwards %llX to %llX\n",329329+ before->cpu, before->pc2, after->pc2);330330+ errors++;331331+ }332332+ if (SUBTRACT_COUNTER(after->pc3, before->pc3, delta->pc3)) {333333+ fprintf(stderr, "cpu%d pc3 counter went backwards %llX to %llX\n",334334+ before->cpu, before->pc3, after->pc3);335335+ errors++;336336+ }337337+ if (SUBTRACT_COUNTER(after->pc6, before->pc6, delta->pc6)) {338338+ fprintf(stderr, "cpu%d pc6 counter went backwards %llX to %llX\n",339339+ before->cpu, before->pc6, after->pc6);340340+ errors++;341341+ }342342+ if (SUBTRACT_COUNTER(after->pc7, before->pc7, delta->pc7)) {343343+ fprintf(stderr, "cpu%d pc7 counter went backwards %llX to %llX\n",344344+ before->cpu, before->pc7, after->pc7);345345+ errors++;346346+ }347347+348348+ perf_err = SUBTRACT_COUNTER(after->aperf, before->aperf, delta->aperf);349349+ if (perf_err) {350350+ fprintf(stderr, "cpu%d aperf counter went backwards %llX to %llX\n",351351+ before->cpu, before->aperf, after->aperf);352352+ }353353+ perf_err |= SUBTRACT_COUNTER(after->mperf, before->mperf, delta->mperf);354354+ if (perf_err) {355355+ fprintf(stderr, "cpu%d mperf counter went backwards %llX to %llX\n",356356+ before->cpu, before->mperf, after->mperf);357357+ }358358+ if (perf_err) {359359+ if (!aperf_mperf_unstable) {360360+ fprintf(stderr, "%s: APERF or MPERF went backwards *\n", progname);361361+ fprintf(stderr, "* Frequency results do not cover entire interval *\n");362362+ fprintf(stderr, "* fix this by running Linux-2.6.30 or later *\n");363363+364364+ aperf_mperf_unstable = 1;365365+ }366366+ /*367367+ * mperf delta is likely a huge "positive" number368368+ * can not use it for calculating c0 time369369+ */370370+ skip_c0 = 1;371371+ skip_c1 = 1;372372+ }373373+374374+ /*375375+ * As mperf and tsc collection are not atomic,376376+ * it is possible for mperf's non-halted cycles377377+ * to exceed TSC's all cycles: show c1 = 0% in that case.378378+ */379379+ if (delta->mperf > delta->tsc)380380+ delta->c1 = 0;381381+ else /* normal case, derive c1 */382382+ delta->c1 = delta->tsc - delta->mperf383383+ - delta->c3 - delta->c6 - delta->c7;384384+385385+ if (delta->mperf == 0)386386+ delta->mperf = 1; /* divide by 0 protection */387387+388388+ /*389389+ * for "extra msr", just copy the latest w/o subtracting390390+ */391391+ delta->extra_msr = after->extra_msr;392392+ if (errors) {393393+ fprintf(stderr, "ERROR cpu%d before:\n", before->cpu);394394+ dump_pcc(before);395395+ fprintf(stderr, "ERROR cpu%d after:\n", before->cpu);396396+ dump_pcc(after);397397+ errors = 0;398398+ }399399+ }400400+ return 0;401401+}402402+403403+void compute_average(PCC *delta, PCC *avg)404404+{405405+ PCC *sum;406406+407407+ sum = calloc(1, sizeof(PCC));408408+ if (sum == NULL) {409409+ perror("calloc sum");410410+ exit(1);411411+ }412412+413413+ for (; delta; delta = delta->next) {414414+ sum->tsc += delta->tsc;415415+ sum->c1 += delta->c1;416416+ sum->c3 += delta->c3;417417+ sum->c6 += delta->c6;418418+ sum->c7 += delta->c7;419419+ sum->aperf += delta->aperf;420420+ sum->mperf += delta->mperf;421421+ sum->pc2 += delta->pc2;422422+ sum->pc3 += delta->pc3;423423+ sum->pc6 += delta->pc6;424424+ sum->pc7 += delta->pc7;425425+ }426426+ avg->tsc = sum->tsc/num_cpus;427427+ avg->c1 = sum->c1/num_cpus;428428+ avg->c3 = sum->c3/num_cpus;429429+ avg->c6 = sum->c6/num_cpus;430430+ avg->c7 = sum->c7/num_cpus;431431+ avg->aperf = sum->aperf/num_cpus;432432+ avg->mperf = sum->mperf/num_cpus;433433+ avg->pc2 = sum->pc2/num_cpus;434434+ avg->pc3 = sum->pc3/num_cpus;435435+ avg->pc6 = sum->pc6/num_cpus;436436+ avg->pc7 = sum->pc7/num_cpus;437437+438438+ free(sum);439439+}440440+441441+void get_counters(PCC *pcc)442442+{443443+ for ( ; pcc; pcc = pcc->next) {444444+ pcc->tsc = get_msr(pcc->cpu, MSR_TSC);445445+ if (do_nhm_cstates)446446+ pcc->c3 = get_msr(pcc->cpu, MSR_CORE_C3_RESIDENCY);447447+ if (do_nhm_cstates)448448+ pcc->c6 = get_msr(pcc->cpu, MSR_CORE_C6_RESIDENCY);449449+ if (do_snb_cstates)450450+ pcc->c7 = get_msr(pcc->cpu, MSR_CORE_C7_RESIDENCY);451451+ if (has_aperf)452452+ pcc->aperf = get_msr(pcc->cpu, MSR_APERF);453453+ if (has_aperf)454454+ pcc->mperf = get_msr(pcc->cpu, MSR_MPERF);455455+ if (do_snb_cstates)456456+ pcc->pc2 = get_msr(pcc->cpu, MSR_PKG_C2_RESIDENCY);457457+ if (do_nhm_cstates)458458+ pcc->pc3 = get_msr(pcc->cpu, MSR_PKG_C3_RESIDENCY);459459+ if (do_nhm_cstates)460460+ pcc->pc6 = get_msr(pcc->cpu, MSR_PKG_C6_RESIDENCY);461461+ if (do_snb_cstates)462462+ pcc->pc7 = get_msr(pcc->cpu, MSR_PKG_C7_RESIDENCY);463463+ if (extra_msr_offset)464464+ pcc->extra_msr = get_msr(pcc->cpu, extra_msr_offset);465465+ }466466+}467467+468468+469469+void print_nehalem_info()470470+{471471+ unsigned long long msr;472472+ unsigned int ratio;473473+474474+ if (!do_nehalem_platform_info)475475+ return;476476+477477+ msr = get_msr(0, MSR_NEHALEM_PLATFORM_INFO);478478+479479+ ratio = (msr >> 40) & 0xFF;480480+ fprintf(stderr, "%d * %.0f = %.0f MHz max efficiency\n",481481+ ratio, bclk, ratio * bclk);482482+483483+ ratio = (msr >> 8) & 0xFF;484484+ fprintf(stderr, "%d * %.0f = %.0f MHz TSC frequency\n",485485+ ratio, bclk, ratio * bclk);486486+487487+ if (verbose > 1)488488+ fprintf(stderr, "MSR_NEHALEM_PLATFORM_INFO: 0x%llx\n", msr);489489+490490+ if (!do_nehalem_turbo_ratio_limit)491491+ return;492492+493493+ msr = get_msr(0, MSR_NEHALEM_TURBO_RATIO_LIMIT);494494+495495+ ratio = (msr >> 24) & 0xFF;496496+ if (ratio)497497+ fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 4 active cores\n",498498+ ratio, bclk, ratio * bclk);499499+500500+ ratio = (msr >> 16) & 0xFF;501501+ if (ratio)502502+ fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 3 active cores\n",503503+ ratio, bclk, ratio * bclk);504504+505505+ ratio = (msr >> 8) & 0xFF;506506+ if (ratio)507507+ fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 2 active cores\n",508508+ ratio, bclk, ratio * bclk);509509+510510+ ratio = (msr >> 0) & 0xFF;511511+ if (ratio)512512+ fprintf(stderr, "%d * %.0f = %.0f MHz max turbo 1 active cores\n",513513+ ratio, bclk, ratio * bclk);514514+515515+}516516+517517+void free_counter_list(PCC *list)518518+{519519+ PCC *p;520520+521521+ for (p = list; p; ) {522522+ PCC *free_me;523523+524524+ free_me = p;525525+ p = p->next;526526+ free(free_me);527527+ }528528+ return;529529+}530530+531531+void free_all_counters(void)532532+{533533+ free_counter_list(pcc_even);534534+ pcc_even = NULL;535535+536536+ free_counter_list(pcc_odd);537537+ pcc_odd = NULL;538538+539539+ free_counter_list(pcc_delta);540540+ pcc_delta = NULL;541541+542542+ free_counter_list(pcc_average);543543+ pcc_average = NULL;544544+}545545+546546+void insert_cpu_counters(PCC **list, PCC *new)547547+{548548+ PCC *prev;549549+550550+ /*551551+ * list was empty552552+ */553553+ if (*list == NULL) {554554+ new->next = *list;555555+ *list = new;556556+ return;557557+ }558558+559559+ show_cpu = 1; /* there is more than one CPU */560560+561561+ /*562562+ * insert on front of list.563563+ * It is sorted by ascending package#, core#, cpu#564564+ */565565+ if (((*list)->pkg > new->pkg) ||566566+ (((*list)->pkg == new->pkg) && ((*list)->core > new->core)) ||567567+ (((*list)->pkg == new->pkg) && ((*list)->core == new->core) && ((*list)->cpu > new->cpu))) {568568+ new->next = *list;569569+ *list = new;570570+ return;571571+ }572572+573573+ prev = *list;574574+575575+ while (prev->next && (prev->next->pkg < new->pkg)) {576576+ prev = prev->next;577577+ show_pkg = 1; /* there is more than 1 package */578578+ }579579+580580+ while (prev->next && (prev->next->pkg == new->pkg)581581+ && (prev->next->core < new->core)) {582582+ prev = prev->next;583583+ show_core = 1; /* there is more than 1 core */584584+ }585585+586586+ while (prev->next && (prev->next->pkg == new->pkg)587587+ && (prev->next->core == new->core)588588+ && (prev->next->cpu < new->cpu)) {589589+ prev = prev->next;590590+ }591591+592592+ /*593593+ * insert after "prev"594594+ */595595+ new->next = prev->next;596596+ prev->next = new;597597+598598+ return;599599+}600600+601601+void alloc_new_cpu_counters(int pkg, int core, int cpu)602602+{603603+ PCC *new;604604+605605+ if (verbose > 1)606606+ printf("pkg%d core%d, cpu%d\n", pkg, core, cpu);607607+608608+ new = (PCC *)calloc(1, sizeof(PCC));609609+ if (new == NULL) {610610+ perror("calloc");611611+ exit(1);612612+ }613613+ new->pkg = pkg;614614+ new->core = core;615615+ new->cpu = cpu;616616+ insert_cpu_counters(&pcc_odd, new);617617+618618+ new = (PCC *)calloc(1, sizeof(PCC));619619+ if (new == NULL) {620620+ perror("calloc");621621+ exit(1);622622+ }623623+ new->pkg = pkg;624624+ new->core = core;625625+ new->cpu = cpu;626626+ insert_cpu_counters(&pcc_even, new);627627+628628+ new = (PCC *)calloc(1, sizeof(PCC));629629+ if (new == NULL) {630630+ perror("calloc");631631+ exit(1);632632+ }633633+ new->pkg = pkg;634634+ new->core = core;635635+ new->cpu = cpu;636636+ insert_cpu_counters(&pcc_delta, new);637637+638638+ new = (PCC *)calloc(1, sizeof(PCC));639639+ if (new == NULL) {640640+ perror("calloc");641641+ exit(1);642642+ }643643+ new->pkg = pkg;644644+ new->core = core;645645+ new->cpu = cpu;646646+ pcc_average = new;647647+}648648+649649+int get_physical_package_id(int cpu)650650+{651651+ char path[64];652652+ FILE *filep;653653+ int pkg;654654+655655+ sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/physical_package_id", cpu);656656+ filep = fopen(path, "r");657657+ if (filep == NULL) {658658+ perror(path);659659+ exit(1);660660+ }661661+ fscanf(filep, "%d", &pkg);662662+ fclose(filep);663663+ return pkg;664664+}665665+666666+int get_core_id(int cpu)667667+{668668+ char path[64];669669+ FILE *filep;670670+ int core;671671+672672+ sprintf(path, "/sys/devices/system/cpu/cpu%d/topology/core_id", cpu);673673+ filep = fopen(path, "r");674674+ if (filep == NULL) {675675+ perror(path);676676+ exit(1);677677+ }678678+ fscanf(filep, "%d", &core);679679+ fclose(filep);680680+ return core;681681+}682682+683683+/*684684+ * run func(index, cpu) on every cpu in /proc/stat685685+ */686686+687687+int for_all_cpus(void (func)(int, int, int))688688+{689689+ FILE *fp;690690+ int cpu_count;691691+ int retval;692692+693693+ fp = fopen(proc_stat, "r");694694+ if (fp == NULL) {695695+ perror(proc_stat);696696+ exit(1);697697+ }698698+699699+ retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");700700+ if (retval != 0) {701701+ perror("/proc/stat format");702702+ exit(1);703703+ }704704+705705+ for (cpu_count = 0; ; cpu_count++) {706706+ int cpu;707707+708708+ retval = fscanf(fp, "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n", &cpu);709709+ if (retval != 1)710710+ break;711711+712712+ func(get_physical_package_id(cpu), get_core_id(cpu), cpu);713713+ }714714+ fclose(fp);715715+ return cpu_count;716716+}717717+718718+void re_initialize(void)719719+{720720+ printf("turbostat: topology changed, re-initializing.\n");721721+ free_all_counters();722722+ num_cpus = for_all_cpus(alloc_new_cpu_counters);723723+ need_reinitialize = 0;724724+ printf("num_cpus is now %d\n", num_cpus);725725+}726726+727727+void dummy(int pkg, int core, int cpu) { return; }728728+/*729729+ * check to see if a cpu came on-line730730+ */731731+void verify_num_cpus()732732+{733733+ int new_num_cpus;734734+735735+ new_num_cpus = for_all_cpus(dummy);736736+737737+ if (new_num_cpus != num_cpus) {738738+ if (verbose)739739+ printf("num_cpus was %d, is now %d\n",740740+ num_cpus, new_num_cpus);741741+ need_reinitialize = 1;742742+ }743743+744744+ return;745745+}746746+747747+void turbostat_loop()748748+{749749+restart:750750+ get_counters(pcc_even);751751+ gettimeofday(&tv_even, (struct timezone *)NULL);752752+753753+ while (1) {754754+ verify_num_cpus();755755+ if (need_reinitialize) {756756+ re_initialize();757757+ goto restart;758758+ }759759+ sleep(interval_sec);760760+ get_counters(pcc_odd);761761+ gettimeofday(&tv_odd, (struct timezone *)NULL);762762+763763+ compute_delta(pcc_odd, pcc_even, pcc_delta);764764+ timersub(&tv_odd, &tv_even, &tv_delta);765765+ compute_average(pcc_delta, pcc_average);766766+ print_counters(pcc_delta);767767+ if (need_reinitialize) {768768+ re_initialize();769769+ goto restart;770770+ }771771+ sleep(interval_sec);772772+ get_counters(pcc_even);773773+ gettimeofday(&tv_even, (struct timezone *)NULL);774774+ compute_delta(pcc_even, pcc_odd, pcc_delta);775775+ timersub(&tv_even, &tv_odd, &tv_delta);776776+ compute_average(pcc_delta, pcc_average);777777+ print_counters(pcc_delta);778778+ }779779+}780780+781781+void check_dev_msr()782782+{783783+ struct stat sb;784784+785785+ if (stat("/dev/cpu/0/msr", &sb)) {786786+ fprintf(stderr, "no /dev/cpu/0/msr\n");787787+ fprintf(stderr, "Try \"# modprobe msr\"\n");788788+ exit(-5);789789+ }790790+}791791+792792+void check_super_user()793793+{794794+ if (getuid() != 0) {795795+ fprintf(stderr, "must be root\n");796796+ exit(-6);797797+ }798798+}799799+800800+int has_nehalem_turbo_ratio_limit(unsigned int family, unsigned int model)801801+{802802+ if (!genuine_intel)803803+ return 0;804804+805805+ if (family != 6)806806+ return 0;807807+808808+ switch (model) {809809+ case 0x1A: /* Core i7, Xeon 5500 series - Bloomfield, Gainstown NHM-EP */810810+ case 0x1E: /* Core i7 and i5 Processor - Clarksfield, Lynnfield, Jasper Forest */811811+ case 0x1F: /* Core i7 and i5 Processor - Nehalem */812812+ case 0x25: /* Westmere Client - Clarkdale, Arrandale */813813+ case 0x2C: /* Westmere EP - Gulftown */814814+ case 0x2A: /* SNB */815815+ case 0x2D: /* SNB Xeon */816816+ return 1;817817+ case 0x2E: /* Nehalem-EX Xeon - Beckton */818818+ case 0x2F: /* Westmere-EX Xeon - Eagleton */819819+ default:820820+ return 0;821821+ }822822+}823823+824824+int is_snb(unsigned int family, unsigned int model)825825+{826826+ if (!genuine_intel)827827+ return 0;828828+829829+ switch (model) {830830+ case 0x2A:831831+ case 0x2D:832832+ return 1;833833+ }834834+ return 0;835835+}836836+837837+double discover_bclk(unsigned int family, unsigned int model)838838+{839839+ if (is_snb(family, model))840840+ return 100.00;841841+ else842842+ return 133.33;843843+}844844+845845+void check_cpuid()846846+{847847+ unsigned int eax, ebx, ecx, edx, max_level;848848+ unsigned int fms, family, model, stepping;849849+850850+ eax = ebx = ecx = edx = 0;851851+852852+ asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0));853853+854854+ if (ebx == 0x756e6547 && edx == 0x49656e69 && ecx == 0x6c65746e)855855+ genuine_intel = 1;856856+857857+ if (verbose)858858+ fprintf(stderr, "%.4s%.4s%.4s ",859859+ (char *)&ebx, (char *)&edx, (char *)&ecx);860860+861861+ asm("cpuid" : "=a" (fms), "=c" (ecx), "=d" (edx) : "a" (1) : "ebx");862862+ family = (fms >> 8) & 0xf;863863+ model = (fms >> 4) & 0xf;864864+ stepping = fms & 0xf;865865+ if (family == 6 || family == 0xf)866866+ model += ((fms >> 16) & 0xf) << 4;867867+868868+ if (verbose)869869+ fprintf(stderr, "%d CPUID levels; family:model:stepping 0x%x:%x:%x (%d:%d:%d)\n",870870+ max_level, family, model, stepping, family, model, stepping);871871+872872+ if (!(edx & (1 << 5))) {873873+ fprintf(stderr, "CPUID: no MSR\n");874874+ exit(1);875875+ }876876+877877+ /*878878+ * check max extended function levels of CPUID.879879+ * This is needed to check for invariant TSC.880880+ * This check is valid for both Intel and AMD.881881+ */882882+ ebx = ecx = edx = 0;883883+ asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x80000000));884884+885885+ if (max_level < 0x80000007) {886886+ fprintf(stderr, "CPUID: no invariant TSC (max_level 0x%x)\n", max_level);887887+ exit(1);888888+ }889889+890890+ /*891891+ * Non-Stop TSC is advertised by CPUID.EAX=0x80000007: EDX.bit8892892+ * this check is valid for both Intel and AMD893893+ */894894+ asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x80000007));895895+ has_invariant_tsc = edx && (1 << 8);896896+897897+ if (!has_invariant_tsc) {898898+ fprintf(stderr, "No invariant TSC\n");899899+ exit(1);900900+ }901901+902902+ /*903903+ * APERF/MPERF is advertised by CPUID.EAX=0x6: ECX.bit0904904+ * this check is valid for both Intel and AMD905905+ */906906+907907+ asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (0x6));908908+ has_aperf = ecx && (1 << 0);909909+ if (!has_aperf) {910910+ fprintf(stderr, "No APERF MSR\n");911911+ exit(1);912912+ }913913+914914+ do_nehalem_platform_info = genuine_intel && has_invariant_tsc;915915+ do_nhm_cstates = genuine_intel; /* all Intel w/ non-stop TSC have NHM counters */916916+ do_snb_cstates = is_snb(family, model);917917+ bclk = discover_bclk(family, model);918918+919919+ do_nehalem_turbo_ratio_limit = has_nehalem_turbo_ratio_limit(family, model);920920+}921921+922922+923923+void usage()924924+{925925+ fprintf(stderr, "%s: [-v] [-M MSR#] [-i interval_sec | command ...]\n",926926+ progname);927927+ exit(1);928928+}929929+930930+931931+/*932932+ * in /dev/cpu/ return success for names that are numbers933933+ * ie. filter out ".", "..", "microcode".934934+ */935935+int dir_filter(const struct dirent *dirp)936936+{937937+ if (isdigit(dirp->d_name[0]))938938+ return 1;939939+ else940940+ return 0;941941+}942942+943943+int open_dev_cpu_msr(int dummy1)944944+{945945+ return 0;946946+}947947+948948+void turbostat_init()949949+{950950+ check_cpuid();951951+952952+ check_dev_msr();953953+ check_super_user();954954+955955+ num_cpus = for_all_cpus(alloc_new_cpu_counters);956956+957957+ if (verbose)958958+ print_nehalem_info();959959+}960960+961961+int fork_it(char **argv)962962+{963963+ int retval;964964+ pid_t child_pid;965965+ get_counters(pcc_even);966966+ gettimeofday(&tv_even, (struct timezone *)NULL);967967+968968+ child_pid = fork();969969+ if (!child_pid) {970970+ /* child */971971+ execvp(argv[0], argv);972972+ } else {973973+ int status;974974+975975+ /* parent */976976+ if (child_pid == -1) {977977+ perror("fork");978978+ exit(1);979979+ }980980+981981+ signal(SIGINT, SIG_IGN);982982+ signal(SIGQUIT, SIG_IGN);983983+ if (waitpid(child_pid, &status, 0) == -1) {984984+ perror("wait");985985+ exit(1);986986+ }987987+ }988988+ get_counters(pcc_odd);989989+ gettimeofday(&tv_odd, (struct timezone *)NULL);990990+ retval = compute_delta(pcc_odd, pcc_even, pcc_delta);991991+992992+ timersub(&tv_odd, &tv_even, &tv_delta);993993+ compute_average(pcc_delta, pcc_average);994994+ if (!retval)995995+ print_counters(pcc_delta);996996+997997+ fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0);;998998+999999+ return 0;10001000+}10011001+10021002+void cmdline(int argc, char **argv)10031003+{10041004+ int opt;10051005+10061006+ progname = argv[0];10071007+10081008+ while ((opt = getopt(argc, argv, "+vi:M:")) != -1) {10091009+ switch (opt) {10101010+ case 'v':10111011+ verbose++;10121012+ break;10131013+ case 'i':10141014+ interval_sec = atoi(optarg);10151015+ break;10161016+ case 'M':10171017+ sscanf(optarg, "%x", &extra_msr_offset);10181018+ if (verbose > 1)10191019+ fprintf(stderr, "MSR 0x%X\n", extra_msr_offset);10201020+ break;10211021+ default:10221022+ usage();10231023+ }10241024+ }10251025+}10261026+10271027+int main(int argc, char **argv)10281028+{10291029+ cmdline(argc, argv);10301030+10311031+ if (verbose > 1)10321032+ fprintf(stderr, "turbostat Dec 6, 2010"10331033+ " - Len Brown <lenb@kernel.org>\n");10341034+ if (verbose > 1)10351035+ fprintf(stderr, "http://userweb.kernel.org/~lenb/acpi/utils/pmtools/turbostat/\n");10361036+10371037+ turbostat_init();10381038+10391039+ /*10401040+ * if any params left, it must be a command to fork10411041+ */10421042+ if (argc - optind)10431043+ return fork_it(argv + optind);10441044+ else10451045+ turbostat_loop();10461046+10471047+ return 0;10481048+}
···11+.\" This page Copyright (C) 2010 Len Brown <len.brown@intel.com>22+.\" Distributed under the GPL, Copyleft 1994.33+.TH X86_ENERGY_PERF_POLICY 844+.SH NAME55+x86_energy_perf_policy \- read or write MSR_IA32_ENERGY_PERF_BIAS66+.SH SYNOPSIS77+.ft B88+.B x86_energy_perf_policy99+.RB [ "\-c cpu" ]1010+.RB [ "\-v" ]1111+.RB "\-r"1212+.br1313+.B x86_energy_perf_policy1414+.RB [ "\-c cpu" ]1515+.RB [ "\-v" ]1616+.RB 'performance'1717+.br1818+.B x86_energy_perf_policy1919+.RB [ "\-c cpu" ]2020+.RB [ "\-v" ]2121+.RB 'normal'2222+.br2323+.B x86_energy_perf_policy2424+.RB [ "\-c cpu" ]2525+.RB [ "\-v" ]2626+.RB 'powersave'2727+.br2828+.B x86_energy_perf_policy2929+.RB [ "\-c cpu" ]3030+.RB [ "\-v" ]3131+.RB n3232+.br3333+.SH DESCRIPTION3434+\fBx86_energy_perf_policy\fP3535+allows software to convey3636+its policy for the relative importance of performance3737+versus energy savings to the processor.3838+3939+The processor uses this information in model-specific ways4040+when it must select trade-offs between performance and4141+energy efficiency.4242+4343+This policy hint does not supersede Processor Performance states4444+(P-states) or CPU Idle power states (C-states), but allows4545+software to have influence where it would otherwise be unable4646+to express a preference.4747+4848+For example, this setting may tell the hardware how4949+aggressively or conservatively to control frequency5050+in the "turbo range" above the explicitly OS-controlled5151+P-state frequency range. It may also tell the hardware5252+how aggressively is should enter the OS requested C-states.5353+5454+Support for this feature is indicated by CPUID.06H.ECX.bit35555+per the Intel Architectures Software Developer's Manual.5656+5757+.SS Options5858+\fB-c\fP limits operation to a single CPU.5959+The default is to operate on all CPUs.6060+Note that MSR_IA32_ENERGY_PERF_BIAS is defined per6161+logical processor, but that the initial implementations6262+of the MSR were shared among all processors in each package.6363+.PP6464+\fB-v\fP increases verbosity. By default6565+x86_energy_perf_policy is silent.6666+.PP6767+\fB-r\fP is for "read-only" mode - the unchanged state6868+is read and displayed.6969+.PP7070+.I performance7171+Set a policy where performance is paramount.7272+The processor will be unwilling to sacrifice any performance7373+for the sake of energy saving. This is the hardware default.7474+.PP7575+.I normal7676+Set a policy with a normal balance between performance and energy efficiency.7777+The processor will tolerate minor performance compromise7878+for potentially significant energy savings.7979+This reasonable default for most desktops and servers.8080+.PP8181+.I powersave8282+Set a policy where the processor can accept8383+a measurable performance hit to maximize energy efficiency.8484+.PP8585+.I n8686+Set MSR_IA32_ENERGY_PERF_BIAS to the specified number.8787+The range of valid numbers is 0-15, where 0 is maximum8888+performance and 15 is maximum energy efficiency.8989+9090+.SH NOTES9191+.B "x86_energy_perf_policy "9292+runs only as root.9393+.SH FILES9494+.ta9595+.nf9696+/dev/cpu/*/msr9797+.fi9898+9999+.SH "SEE ALSO"100100+msr(4)101101+.PP102102+.SH AUTHORS103103+.nf104104+Written by Len Brown <len.brown@intel.com>
···11+/*22+ * x86_energy_perf_policy -- set the energy versus performance33+ * policy preference bias on recent X86 processors.44+ */55+/*66+ * Copyright (c) 2010, Intel Corporation.77+ * Len Brown <len.brown@intel.com>88+ *99+ * This program is free software; you can redistribute it and/or modify it1010+ * under the terms and conditions of the GNU General Public License,1111+ * version 2, as published by the Free Software Foundation.1212+ *1313+ * This program is distributed in the hope it will be useful, but WITHOUT1414+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or1515+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for1616+ * more details.1717+ *1818+ * You should have received a copy of the GNU General Public License along with1919+ * this program; if not, write to the Free Software Foundation, Inc.,2020+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.2121+ */2222+2323+#include <stdio.h>2424+#include <unistd.h>2525+#include <sys/types.h>2626+#include <sys/stat.h>2727+#include <sys/resource.h>2828+#include <fcntl.h>2929+#include <signal.h>3030+#include <sys/time.h>3131+#include <stdlib.h>3232+#include <string.h>3333+3434+unsigned int verbose; /* set with -v */3535+unsigned int read_only; /* set with -r */3636+char *progname;3737+unsigned long long new_bias;3838+int cpu = -1;3939+4040+/*4141+ * Usage:4242+ *4343+ * -c cpu: limit action to a single CPU (default is all CPUs)4444+ * -v: verbose output (can invoke more than once)4545+ * -r: read-only, don't change any settings4646+ *4747+ * performance4848+ * Performance is paramount.4949+ * Unwilling to sacrafice any performance5050+ * for the sake of energy saving. (hardware default)5151+ *5252+ * normal5353+ * Can tolerate minor performance compromise5454+ * for potentially significant energy savings.5555+ * (reasonable default for most desktops and servers)5656+ *5757+ * powersave5858+ * Can tolerate significant performance hit5959+ * to maximize energy savings.6060+ *6161+ * n6262+ * a numerical value to write to the underlying MSR.6363+ */6464+void usage(void)6565+{6666+ printf("%s: [-c cpu] [-v] "6767+ "(-r | 'performance' | 'normal' | 'powersave' | n)\n",6868+ progname);6969+ exit(1);7070+}7171+7272+#define MSR_IA32_ENERGY_PERF_BIAS 0x000001b07373+7474+#define BIAS_PERFORMANCE 07575+#define BIAS_BALANCE 67676+#define BIAS_POWERSAVE 157777+7878+void cmdline(int argc, char **argv)7979+{8080+ int opt;8181+8282+ progname = argv[0];8383+8484+ while ((opt = getopt(argc, argv, "+rvc:")) != -1) {8585+ switch (opt) {8686+ case 'c':8787+ cpu = atoi(optarg);8888+ break;8989+ case 'r':9090+ read_only = 1;9191+ break;9292+ case 'v':9393+ verbose++;9494+ break;9595+ default:9696+ usage();9797+ }9898+ }9999+ /* if -r, then should be no additional optind */100100+ if (read_only && (argc > optind))101101+ usage();102102+103103+ /*104104+ * if no -r , then must be one additional optind105105+ */106106+ if (!read_only) {107107+108108+ if (argc != optind + 1) {109109+ printf("must supply -r or policy param\n");110110+ usage();111111+ }112112+113113+ if (!strcmp("performance", argv[optind])) {114114+ new_bias = BIAS_PERFORMANCE;115115+ } else if (!strcmp("normal", argv[optind])) {116116+ new_bias = BIAS_BALANCE;117117+ } else if (!strcmp("powersave", argv[optind])) {118118+ new_bias = BIAS_POWERSAVE;119119+ } else {120120+ char *endptr;121121+122122+ new_bias = strtoull(argv[optind], &endptr, 0);123123+ if (endptr == argv[optind] ||124124+ new_bias > BIAS_POWERSAVE) {125125+ fprintf(stderr, "invalid value: %s\n",126126+ argv[optind]);127127+ usage();128128+ }129129+ }130130+ }131131+}132132+133133+/*134134+ * validate_cpuid()135135+ * returns on success, quietly exits on failure (make verbose with -v)136136+ */137137+void validate_cpuid(void)138138+{139139+ unsigned int eax, ebx, ecx, edx, max_level;140140+ char brand[16];141141+ unsigned int fms, family, model, stepping;142142+143143+ eax = ebx = ecx = edx = 0;144144+145145+ asm("cpuid" : "=a" (max_level), "=b" (ebx), "=c" (ecx),146146+ "=d" (edx) : "a" (0));147147+148148+ if (ebx != 0x756e6547 || edx != 0x49656e69 || ecx != 0x6c65746e) {149149+ if (verbose)150150+ fprintf(stderr, "%.4s%.4s%.4s != GenuineIntel",151151+ (char *)&ebx, (char *)&edx, (char *)&ecx);152152+ exit(1);153153+ }154154+155155+ asm("cpuid" : "=a" (fms), "=c" (ecx), "=d" (edx) : "a" (1) : "ebx");156156+ family = (fms >> 8) & 0xf;157157+ model = (fms >> 4) & 0xf;158158+ stepping = fms & 0xf;159159+ if (family == 6 || family == 0xf)160160+ model += ((fms >> 16) & 0xf) << 4;161161+162162+ if (verbose > 1)163163+ printf("CPUID %s %d levels family:model:stepping "164164+ "0x%x:%x:%x (%d:%d:%d)\n", brand, max_level,165165+ family, model, stepping, family, model, stepping);166166+167167+ if (!(edx & (1 << 5))) {168168+ if (verbose)169169+ printf("CPUID: no MSR\n");170170+ exit(1);171171+ }172172+173173+ /*174174+ * Support for MSR_IA32_ENERGY_PERF_BIAS175175+ * is indicated by CPUID.06H.ECX.bit3176176+ */177177+ asm("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (6));178178+ if (verbose)179179+ printf("CPUID.06H.ECX: 0x%x\n", ecx);180180+ if (!(ecx & (1 << 3))) {181181+ if (verbose)182182+ printf("CPUID: No MSR_IA32_ENERGY_PERF_BIAS\n");183183+ exit(1);184184+ }185185+ return; /* success */186186+}187187+188188+unsigned long long get_msr(int cpu, int offset)189189+{190190+ unsigned long long msr;191191+ char msr_path[32];192192+ int retval;193193+ int fd;194194+195195+ sprintf(msr_path, "/dev/cpu/%d/msr", cpu);196196+ fd = open(msr_path, O_RDONLY);197197+ if (fd < 0) {198198+ printf("Try \"# modprobe msr\"\n");199199+ perror(msr_path);200200+ exit(1);201201+ }202202+203203+ retval = pread(fd, &msr, sizeof msr, offset);204204+205205+ if (retval != sizeof msr) {206206+ printf("pread cpu%d 0x%x = %d\n", cpu, offset, retval);207207+ exit(-2);208208+ }209209+ close(fd);210210+ return msr;211211+}212212+213213+unsigned long long put_msr(int cpu, unsigned long long new_msr, int offset)214214+{215215+ unsigned long long old_msr;216216+ char msr_path[32];217217+ int retval;218218+ int fd;219219+220220+ sprintf(msr_path, "/dev/cpu/%d/msr", cpu);221221+ fd = open(msr_path, O_RDWR);222222+ if (fd < 0) {223223+ perror(msr_path);224224+ exit(1);225225+ }226226+227227+ retval = pread(fd, &old_msr, sizeof old_msr, offset);228228+ if (retval != sizeof old_msr) {229229+ perror("pwrite");230230+ printf("pread cpu%d 0x%x = %d\n", cpu, offset, retval);231231+ exit(-2);232232+ }233233+234234+ retval = pwrite(fd, &new_msr, sizeof new_msr, offset);235235+ if (retval != sizeof new_msr) {236236+ perror("pwrite");237237+ printf("pwrite cpu%d 0x%x = %d\n", cpu, offset, retval);238238+ exit(-2);239239+ }240240+241241+ close(fd);242242+243243+ return old_msr;244244+}245245+246246+void print_msr(int cpu)247247+{248248+ printf("cpu%d: 0x%016llx\n",249249+ cpu, get_msr(cpu, MSR_IA32_ENERGY_PERF_BIAS));250250+}251251+252252+void update_msr(int cpu)253253+{254254+ unsigned long long previous_msr;255255+256256+ previous_msr = put_msr(cpu, new_bias, MSR_IA32_ENERGY_PERF_BIAS);257257+258258+ if (verbose)259259+ printf("cpu%d msr0x%x 0x%016llx -> 0x%016llx\n",260260+ cpu, MSR_IA32_ENERGY_PERF_BIAS, previous_msr, new_bias);261261+262262+ return;263263+}264264+265265+char *proc_stat = "/proc/stat";266266+/*267267+ * run func() on every cpu in /dev/cpu268268+ */269269+void for_every_cpu(void (func)(int))270270+{271271+ FILE *fp;272272+ int retval;273273+274274+ fp = fopen(proc_stat, "r");275275+ if (fp == NULL) {276276+ perror(proc_stat);277277+ exit(1);278278+ }279279+280280+ retval = fscanf(fp, "cpu %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n");281281+ if (retval != 0) {282282+ perror("/proc/stat format");283283+ exit(1);284284+ }285285+286286+ while (1) {287287+ int cpu;288288+289289+ retval = fscanf(fp,290290+ "cpu%u %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d\n",291291+ &cpu);292292+ if (retval != 1)293293+ return;294294+295295+ func(cpu);296296+ }297297+ fclose(fp);298298+}299299+300300+int main(int argc, char **argv)301301+{302302+ cmdline(argc, argv);303303+304304+ if (verbose > 1)305305+ printf("x86_energy_perf_policy Nov 24, 2010"306306+ " - Len Brown <lenb@kernel.org>\n");307307+ if (verbose > 1 && !read_only)308308+ printf("new_bias %lld\n", new_bias);309309+310310+ validate_cpuid();311311+312312+ if (cpu != -1) {313313+ if (read_only)314314+ print_msr(cpu);315315+ else316316+ update_msr(cpu);317317+ } else {318318+ if (read_only)319319+ for_every_cpu(print_msr);320320+ else321321+ for_every_cpu(update_msr);322322+ }323323+324324+ return 0;325325+}
···11+#!/usr/bin/perl -w22+#33+# Copywrite 2010 - Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.44+# Licensed under the terms of the GNU GPL License version 255+#66+77+use strict;88+use IPC::Open2;99+use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);1010+use File::Path qw(mkpath);1111+use File::Copy qw(cp);1212+use FileHandle;1313+1414+my $VERSION = "0.2";1515+1616+$| = 1;1717+1818+my %opt;1919+my %repeat_tests;2020+my %repeats;2121+my %default;2222+2323+#default opts2424+$default{"NUM_TESTS"} = 1;2525+$default{"REBOOT_TYPE"} = "grub";2626+$default{"TEST_TYPE"} = "test";2727+$default{"BUILD_TYPE"} = "randconfig";2828+$default{"MAKE_CMD"} = "make";2929+$default{"TIMEOUT"} = 120;3030+$default{"TMP_DIR"} = "/tmp/ktest";3131+$default{"SLEEP_TIME"} = 60; # sleep time between tests3232+$default{"BUILD_NOCLEAN"} = 0;3333+$default{"REBOOT_ON_ERROR"} = 0;3434+$default{"POWEROFF_ON_ERROR"} = 0;3535+$default{"REBOOT_ON_SUCCESS"} = 1;3636+$default{"POWEROFF_ON_SUCCESS"} = 0;3737+$default{"BUILD_OPTIONS"} = "";3838+$default{"BISECT_SLEEP_TIME"} = 60; # sleep time between bisects3939+$default{"CLEAR_LOG"} = 0;4040+$default{"SUCCESS_LINE"} = "login:";4141+$default{"BOOTED_TIMEOUT"} = 1;4242+$default{"DIE_ON_FAILURE"} = 1;4343+$default{"SSH_EXEC"} = "ssh \$SSH_USER\@\$MACHINE \$SSH_COMMAND";4444+$default{"SCP_TO_TARGET"} = "scp \$SRC_FILE \$SSH_USER\@\$MACHINE:\$DST_FILE";4545+$default{"REBOOT"} = "ssh \$SSH_USER\@\$MACHINE reboot";4646+$default{"STOP_AFTER_SUCCESS"} = 10;4747+$default{"STOP_AFTER_FAILURE"} = 60;4848+$default{"LOCALVERSION"} = "-test";4949+5050+my $ktest_config;5151+my $version;5252+my $machine;5353+my $ssh_user;5454+my $tmpdir;5555+my $builddir;5656+my $outputdir;5757+my $output_config;5858+my $test_type;5959+my $build_type;6060+my $build_options;6161+my $reboot_type;6262+my $reboot_script;6363+my $power_cycle;6464+my $reboot;6565+my $reboot_on_error;6666+my $poweroff_on_error;6767+my $die_on_failure;6868+my $powercycle_after_reboot;6969+my $poweroff_after_halt;7070+my $ssh_exec;7171+my $scp_to_target;7272+my $power_off;7373+my $grub_menu;7474+my $grub_number;7575+my $target;7676+my $make;7777+my $post_install;7878+my $noclean;7979+my $minconfig;8080+my $addconfig;8181+my $in_bisect = 0;8282+my $bisect_bad = "";8383+my $reverse_bisect;8484+my $in_patchcheck = 0;8585+my $run_test;8686+my $redirect;8787+my $buildlog;8888+my $dmesg;8989+my $monitor_fp;9090+my $monitor_pid;9191+my $monitor_cnt = 0;9292+my $sleep_time;9393+my $bisect_sleep_time;9494+my $store_failures;9595+my $timeout;9696+my $booted_timeout;9797+my $console;9898+my $success_line;9999+my $stop_after_success;100100+my $stop_after_failure;101101+my $build_target;102102+my $target_image;103103+my $localversion;104104+my $iteration = 0;105105+my $successes = 0;106106+107107+my %entered_configs;108108+my %config_help;109109+110110+$config_help{"MACHINE"} = << "EOF"111111+ The machine hostname that you will test.112112+EOF113113+ ;114114+$config_help{"SSH_USER"} = << "EOF"115115+ The box is expected to have ssh on normal bootup, provide the user116116+ (most likely root, since you need privileged operations)117117+EOF118118+ ;119119+$config_help{"BUILD_DIR"} = << "EOF"120120+ The directory that contains the Linux source code (full path).121121+EOF122122+ ;123123+$config_help{"OUTPUT_DIR"} = << "EOF"124124+ The directory that the objects will be built (full path).125125+ (can not be same as BUILD_DIR)126126+EOF127127+ ;128128+$config_help{"BUILD_TARGET"} = << "EOF"129129+ The location of the compiled file to copy to the target.130130+ (relative to OUTPUT_DIR)131131+EOF132132+ ;133133+$config_help{"TARGET_IMAGE"} = << "EOF"134134+ The place to put your image on the test machine.135135+EOF136136+ ;137137+$config_help{"POWER_CYCLE"} = << "EOF"138138+ A script or command to reboot the box.139139+140140+ Here is a digital loggers power switch example141141+ POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin\@power/outlet?5=CCL'142142+143143+ Here is an example to reboot a virtual box on the current host144144+ with the name "Guest".145145+ POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest146146+EOF147147+ ;148148+$config_help{"CONSOLE"} = << "EOF"149149+ The script or command that reads the console150150+151151+ If you use ttywatch server, something like the following would work.152152+CONSOLE = nc -d localhost 3001153153+154154+ For a virtual machine with guest name "Guest".155155+CONSOLE = virsh console Guest156156+EOF157157+ ;158158+$config_help{"LOCALVERSION"} = << "EOF"159159+ Required version ending to differentiate the test160160+ from other linux builds on the system.161161+EOF162162+ ;163163+$config_help{"REBOOT_TYPE"} = << "EOF"164164+ Way to reboot the box to the test kernel.165165+ Only valid options so far are "grub" and "script".166166+167167+ If you specify grub, it will assume grub version 1168168+ and will search in /boot/grub/menu.lst for the title \$GRUB_MENU169169+ and select that target to reboot to the kernel. If this is not170170+ your setup, then specify "script" and have a command or script171171+ specified in REBOOT_SCRIPT to boot to the target.172172+173173+ The entry in /boot/grub/menu.lst must be entered in manually.174174+ The test will not modify that file.175175+EOF176176+ ;177177+$config_help{"GRUB_MENU"} = << "EOF"178178+ The grub title name for the test kernel to boot179179+ (Only mandatory if REBOOT_TYPE = grub)180180+181181+ Note, ktest.pl will not update the grub menu.lst, you need to182182+ manually add an option for the test. ktest.pl will search183183+ the grub menu.lst for this option to find what kernel to184184+ reboot into.185185+186186+ For example, if in the /boot/grub/menu.lst the test kernel title has:187187+ title Test Kernel188188+ kernel vmlinuz-test189189+ GRUB_MENU = Test Kernel190190+EOF191191+ ;192192+$config_help{"REBOOT_SCRIPT"} = << "EOF"193193+ A script to reboot the target into the test kernel194194+ (Only mandatory if REBOOT_TYPE = script)195195+EOF196196+ ;197197+198198+199199+sub get_ktest_config {200200+ my ($config) = @_;201201+202202+ return if (defined($opt{$config}));203203+204204+ if (defined($config_help{$config})) {205205+ print "\n";206206+ print $config_help{$config};207207+ }208208+209209+ for (;;) {210210+ print "$config = ";211211+ if (defined($default{$config})) {212212+ print "\[$default{$config}\] ";213213+ }214214+ $entered_configs{$config} = <STDIN>;215215+ $entered_configs{$config} =~ s/^\s*(.*\S)\s*$/$1/;216216+ if ($entered_configs{$config} =~ /^\s*$/) {217217+ if ($default{$config}) {218218+ $entered_configs{$config} = $default{$config};219219+ } else {220220+ print "Your answer can not be blank\n";221221+ next;222222+ }223223+ }224224+ last;225225+ }226226+}227227+228228+sub get_ktest_configs {229229+ get_ktest_config("MACHINE");230230+ get_ktest_config("SSH_USER");231231+ get_ktest_config("BUILD_DIR");232232+ get_ktest_config("OUTPUT_DIR");233233+ get_ktest_config("BUILD_TARGET");234234+ get_ktest_config("TARGET_IMAGE");235235+ get_ktest_config("POWER_CYCLE");236236+ get_ktest_config("CONSOLE");237237+ get_ktest_config("LOCALVERSION");238238+239239+ my $rtype = $opt{"REBOOT_TYPE"};240240+241241+ if (!defined($rtype)) {242242+ if (!defined($opt{"GRUB_MENU"})) {243243+ get_ktest_config("REBOOT_TYPE");244244+ $rtype = $entered_configs{"REBOOT_TYPE"};245245+ } else {246246+ $rtype = "grub";247247+ }248248+ }249249+250250+ if ($rtype eq "grub") {251251+ get_ktest_config("GRUB_MENU");252252+ } else {253253+ get_ktest_config("REBOOT_SCRIPT");254254+ }255255+}256256+257257+sub set_value {258258+ my ($lvalue, $rvalue) = @_;259259+260260+ if (defined($opt{$lvalue})) {261261+ die "Error: Option $lvalue defined more than once!\n";262262+ }263263+ if ($rvalue =~ /^\s*$/) {264264+ delete $opt{$lvalue};265265+ } else {266266+ $opt{$lvalue} = $rvalue;267267+ }268268+}269269+270270+sub read_config {271271+ my ($config) = @_;272272+273273+ open(IN, $config) || die "can't read file $config";274274+275275+ my $name = $config;276276+ $name =~ s,.*/(.*),$1,;277277+278278+ my $test_num = 0;279279+ my $default = 1;280280+ my $repeat = 1;281281+ my $num_tests_set = 0;282282+ my $skip = 0;283283+ my $rest;284284+285285+ while (<IN>) {286286+287287+ # ignore blank lines and comments288288+ next if (/^\s*$/ || /\s*\#/);289289+290290+ if (/^\s*TEST_START(.*)/) {291291+292292+ $rest = $1;293293+294294+ if ($num_tests_set) {295295+ die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";296296+ }297297+298298+ my $old_test_num = $test_num;299299+ my $old_repeat = $repeat;300300+301301+ $test_num += $repeat;302302+ $default = 0;303303+ $repeat = 1;304304+305305+ if ($rest =~ /\s+SKIP(.*)/) {306306+ $rest = $1;307307+ $skip = 1;308308+ } else {309309+ $skip = 0;310310+ }311311+312312+ if ($rest =~ /\s+ITERATE\s+(\d+)(.*)$/) {313313+ $repeat = $1;314314+ $rest = $2;315315+ $repeat_tests{"$test_num"} = $repeat;316316+ }317317+318318+ if ($rest =~ /\s+SKIP(.*)/) {319319+ $rest = $1;320320+ $skip = 1;321321+ }322322+323323+ if ($rest !~ /^\s*$/) {324324+ die "$name: $.: Gargbage found after TEST_START\n$_";325325+ }326326+327327+ if ($skip) {328328+ $test_num = $old_test_num;329329+ $repeat = $old_repeat;330330+ }331331+332332+ } elsif (/^\s*DEFAULTS(.*)$/) {333333+ $default = 1;334334+335335+ $rest = $1;336336+337337+ if ($rest =~ /\s+SKIP(.*)/) {338338+ $rest = $1;339339+ $skip = 1;340340+ } else {341341+ $skip = 0;342342+ }343343+344344+ if ($rest !~ /^\s*$/) {345345+ die "$name: $.: Gargbage found after DEFAULTS\n$_";346346+ }347347+348348+ } elsif (/^\s*([A-Z_\[\]\d]+)\s*=\s*(.*?)\s*$/) {349349+350350+ next if ($skip);351351+352352+ my $lvalue = $1;353353+ my $rvalue = $2;354354+355355+ if (!$default &&356356+ ($lvalue eq "NUM_TESTS" ||357357+ $lvalue eq "LOG_FILE" ||358358+ $lvalue eq "CLEAR_LOG")) {359359+ die "$name: $.: $lvalue must be set in DEFAULTS section\n";360360+ }361361+362362+ if ($lvalue eq "NUM_TESTS") {363363+ if ($test_num) {364364+ die "$name: $.: Can not specify both NUM_TESTS and TEST_START\n";365365+ }366366+ if (!$default) {367367+ die "$name: $.: NUM_TESTS must be set in default section\n";368368+ }369369+ $num_tests_set = 1;370370+ }371371+372372+ if ($default || $lvalue =~ /\[\d+\]$/) {373373+ set_value($lvalue, $rvalue);374374+ } else {375375+ my $val = "$lvalue\[$test_num\]";376376+ set_value($val, $rvalue);377377+378378+ if ($repeat > 1) {379379+ $repeats{$val} = $repeat;380380+ }381381+ }382382+ } else {383383+ die "$name: $.: Garbage found in config\n$_";384384+ }385385+ }386386+387387+ close(IN);388388+389389+ if ($test_num) {390390+ $test_num += $repeat - 1;391391+ $opt{"NUM_TESTS"} = $test_num;392392+ }393393+394394+ # make sure we have all mandatory configs395395+ get_ktest_configs;396396+397397+ # set any defaults398398+399399+ foreach my $default (keys %default) {400400+ if (!defined($opt{$default})) {401401+ $opt{$default} = $default{$default};402402+ }403403+ }404404+}405405+406406+sub _logit {407407+ if (defined($opt{"LOG_FILE"})) {408408+ open(OUT, ">> $opt{LOG_FILE}") or die "Can't write to $opt{LOG_FILE}";409409+ print OUT @_;410410+ close(OUT);411411+ }412412+}413413+414414+sub logit {415415+ if (defined($opt{"LOG_FILE"})) {416416+ _logit @_;417417+ } else {418418+ print @_;419419+ }420420+}421421+422422+sub doprint {423423+ print @_;424424+ _logit @_;425425+}426426+427427+sub run_command;428428+429429+sub reboot {430430+ # try to reboot normally431431+ if (run_command $reboot) {432432+ if (defined($powercycle_after_reboot)) {433433+ sleep $powercycle_after_reboot;434434+ run_command "$power_cycle";435435+ }436436+ } else {437437+ # nope? power cycle it.438438+ run_command "$power_cycle";439439+ }440440+}441441+442442+sub do_not_reboot {443443+ my $i = $iteration;444444+445445+ return $test_type eq "build" ||446446+ ($test_type eq "patchcheck" && $opt{"PATCHCHECK_TYPE[$i]"} eq "build") ||447447+ ($test_type eq "bisect" && $opt{"BISECT_TYPE[$i]"} eq "build");448448+}449449+450450+sub dodie {451451+ doprint "CRITICAL FAILURE... ", @_, "\n";452452+453453+ my $i = $iteration;454454+455455+ if ($reboot_on_error && !do_not_reboot) {456456+457457+ doprint "REBOOTING\n";458458+ reboot;459459+460460+ } elsif ($poweroff_on_error && defined($power_off)) {461461+ doprint "POWERING OFF\n";462462+ `$power_off`;463463+ }464464+465465+ die @_, "\n";466466+}467467+468468+sub open_console {469469+ my ($fp) = @_;470470+471471+ my $flags;472472+473473+ my $pid = open($fp, "$console|") or474474+ dodie "Can't open console $console";475475+476476+ $flags = fcntl($fp, F_GETFL, 0) or477477+ dodie "Can't get flags for the socket: $!";478478+ $flags = fcntl($fp, F_SETFL, $flags | O_NONBLOCK) or479479+ dodie "Can't set flags for the socket: $!";480480+481481+ return $pid;482482+}483483+484484+sub close_console {485485+ my ($fp, $pid) = @_;486486+487487+ doprint "kill child process $pid\n";488488+ kill 2, $pid;489489+490490+ print "closing!\n";491491+ close($fp);492492+}493493+494494+sub start_monitor {495495+ if ($monitor_cnt++) {496496+ return;497497+ }498498+ $monitor_fp = \*MONFD;499499+ $monitor_pid = open_console $monitor_fp;500500+501501+ return;502502+503503+ open(MONFD, "Stop perl from warning about single use of MONFD");504504+}505505+506506+sub end_monitor {507507+ if (--$monitor_cnt) {508508+ return;509509+ }510510+ close_console($monitor_fp, $monitor_pid);511511+}512512+513513+sub wait_for_monitor {514514+ my ($time) = @_;515515+ my $line;516516+517517+ doprint "** Wait for monitor to settle down **\n";518518+519519+ # read the monitor and wait for the system to calm down520520+ do {521521+ $line = wait_for_input($monitor_fp, $time);522522+ print "$line" if (defined($line));523523+ } while (defined($line));524524+ print "** Monitor flushed **\n";525525+}526526+527527+sub fail {528528+529529+ if ($die_on_failure) {530530+ dodie @_;531531+ }532532+533533+ doprint "FAILED\n";534534+535535+ my $i = $iteration;536536+537537+ # no need to reboot for just building.538538+ if (!do_not_reboot) {539539+ doprint "REBOOTING\n";540540+ reboot;541541+ start_monitor;542542+ wait_for_monitor $sleep_time;543543+ end_monitor;544544+ }545545+546546+ doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";547547+ doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";548548+ doprint "KTEST RESULT: TEST $i Failed: ", @_, "\n";549549+ doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";550550+ doprint "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n";551551+552552+ return 1 if (!defined($store_failures));553553+554554+ my @t = localtime;555555+ my $date = sprintf "%04d%02d%02d%02d%02d%02d",556556+ 1900+$t[5],$t[4],$t[3],$t[2],$t[1],$t[0];557557+558558+ my $type = $build_type;559559+ if ($type =~ /useconfig/) {560560+ $type = "useconfig";561561+ }562562+563563+ my $dir = "$machine-$test_type-$type-fail-$date";564564+ my $faildir = "$store_failures/$dir";565565+566566+ if (!-d $faildir) {567567+ mkpath($faildir) or568568+ die "can't create $faildir";569569+ }570570+ if (-f "$output_config") {571571+ cp "$output_config", "$faildir/config" or572572+ die "failed to copy .config";573573+ }574574+ if (-f $buildlog) {575575+ cp $buildlog, "$faildir/buildlog" or576576+ die "failed to move $buildlog";577577+ }578578+ if (-f $dmesg) {579579+ cp $dmesg, "$faildir/dmesg" or580580+ die "failed to move $dmesg";581581+ }582582+583583+ doprint "*** Saved info to $faildir ***\n";584584+585585+ return 1;586586+}587587+588588+sub run_command {589589+ my ($command) = @_;590590+ my $dolog = 0;591591+ my $dord = 0;592592+ my $pid;593593+594594+ $command =~ s/\$SSH_USER/$ssh_user/g;595595+ $command =~ s/\$MACHINE/$machine/g;596596+597597+ doprint("$command ... ");598598+599599+ $pid = open(CMD, "$command 2>&1 |") or600600+ (fail "unable to exec $command" and return 0);601601+602602+ if (defined($opt{"LOG_FILE"})) {603603+ open(LOG, ">>$opt{LOG_FILE}") or604604+ dodie "failed to write to log";605605+ $dolog = 1;606606+ }607607+608608+ if (defined($redirect)) {609609+ open (RD, ">$redirect") or610610+ dodie "failed to write to redirect $redirect";611611+ $dord = 1;612612+ }613613+614614+ while (<CMD>) {615615+ print LOG if ($dolog);616616+ print RD if ($dord);617617+ }618618+619619+ waitpid($pid, 0);620620+ my $failed = $?;621621+622622+ close(CMD);623623+ close(LOG) if ($dolog);624624+ close(RD) if ($dord);625625+626626+ if ($failed) {627627+ doprint "FAILED!\n";628628+ } else {629629+ doprint "SUCCESS\n";630630+ }631631+632632+ return !$failed;633633+}634634+635635+sub run_ssh {636636+ my ($cmd) = @_;637637+ my $cp_exec = $ssh_exec;638638+639639+ $cp_exec =~ s/\$SSH_COMMAND/$cmd/g;640640+ return run_command "$cp_exec";641641+}642642+643643+sub run_scp {644644+ my ($src, $dst) = @_;645645+ my $cp_scp = $scp_to_target;646646+647647+ $cp_scp =~ s/\$SRC_FILE/$src/g;648648+ $cp_scp =~ s/\$DST_FILE/$dst/g;649649+650650+ return run_command "$cp_scp";651651+}652652+653653+sub get_grub_index {654654+655655+ if ($reboot_type ne "grub") {656656+ return;657657+ }658658+ return if (defined($grub_number));659659+660660+ doprint "Find grub menu ... ";661661+ $grub_number = -1;662662+663663+ my $ssh_grub = $ssh_exec;664664+ $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g;665665+666666+ open(IN, "$ssh_grub |")667667+ or die "unable to get menu.lst";668668+669669+ while (<IN>) {670670+ if (/^\s*title\s+$grub_menu\s*$/) {671671+ $grub_number++;672672+ last;673673+ } elsif (/^\s*title\s/) {674674+ $grub_number++;675675+ }676676+ }677677+ close(IN);678678+679679+ die "Could not find '$grub_menu' in /boot/grub/menu on $machine"680680+ if ($grub_number < 0);681681+ doprint "$grub_number\n";682682+}683683+684684+sub wait_for_input685685+{686686+ my ($fp, $time) = @_;687687+ my $rin;688688+ my $ready;689689+ my $line;690690+ my $ch;691691+692692+ if (!defined($time)) {693693+ $time = $timeout;694694+ }695695+696696+ $rin = '';697697+ vec($rin, fileno($fp), 1) = 1;698698+ $ready = select($rin, undef, undef, $time);699699+700700+ $line = "";701701+702702+ # try to read one char at a time703703+ while (sysread $fp, $ch, 1) {704704+ $line .= $ch;705705+ last if ($ch eq "\n");706706+ }707707+708708+ if (!length($line)) {709709+ return undef;710710+ }711711+712712+ return $line;713713+}714714+715715+sub reboot_to {716716+ if ($reboot_type eq "grub") {717717+ run_ssh "'(echo \"savedefault --default=$grub_number --once\" | grub --batch; reboot)'";718718+ return;719719+ }720720+721721+ run_command "$reboot_script";722722+}723723+724724+sub get_sha1 {725725+ my ($commit) = @_;726726+727727+ doprint "git rev-list --max-count=1 $commit ... ";728728+ my $sha1 = `git rev-list --max-count=1 $commit`;729729+ my $ret = $?;730730+731731+ logit $sha1;732732+733733+ if ($ret) {734734+ doprint "FAILED\n";735735+ dodie "Failed to get git $commit";736736+ }737737+738738+ print "SUCCESS\n";739739+740740+ chomp $sha1;741741+742742+ return $sha1;743743+}744744+745745+sub monitor {746746+ my $booted = 0;747747+ my $bug = 0;748748+ my $skip_call_trace = 0;749749+ my $loops;750750+751751+ wait_for_monitor 5;752752+753753+ my $line;754754+ my $full_line = "";755755+756756+ open(DMESG, "> $dmesg") or757757+ die "unable to write to $dmesg";758758+759759+ reboot_to;760760+761761+ my $success_start;762762+ my $failure_start;763763+764764+ for (;;) {765765+766766+ if ($booted) {767767+ $line = wait_for_input($monitor_fp, $booted_timeout);768768+ } else {769769+ $line = wait_for_input($monitor_fp);770770+ }771771+772772+ last if (!defined($line));773773+774774+ doprint $line;775775+ print DMESG $line;776776+777777+ # we are not guaranteed to get a full line778778+ $full_line .= $line;779779+780780+ if ($full_line =~ /$success_line/) {781781+ $booted = 1;782782+ $success_start = time;783783+ }784784+785785+ if ($booted && defined($stop_after_success) &&786786+ $stop_after_success >= 0) {787787+ my $now = time;788788+ if ($now - $success_start >= $stop_after_success) {789789+ doprint "Test forced to stop after $stop_after_success seconds after success\n";790790+ last;791791+ }792792+ }793793+794794+ if ($full_line =~ /\[ backtrace testing \]/) {795795+ $skip_call_trace = 1;796796+ }797797+798798+ if ($full_line =~ /call trace:/i) {799799+ if (!$skip_call_trace) {800800+ $bug = 1;801801+ $failure_start = time;802802+ }803803+ }804804+805805+ if ($bug && defined($stop_after_failure) &&806806+ $stop_after_failure >= 0) {807807+ my $now = time;808808+ if ($now - $failure_start >= $stop_after_failure) {809809+ doprint "Test forced to stop after $stop_after_failure seconds after failure\n";810810+ last;811811+ }812812+ }813813+814814+ if ($full_line =~ /\[ end of backtrace testing \]/) {815815+ $skip_call_trace = 0;816816+ }817817+818818+ if ($full_line =~ /Kernel panic -/) {819819+ $bug = 1;820820+ }821821+822822+ if ($line =~ /\n/) {823823+ $full_line = "";824824+ }825825+ }826826+827827+ close(DMESG);828828+829829+ if ($bug) {830830+ return 0 if ($in_bisect);831831+ fail "failed - got a bug report" and return 0;832832+ }833833+834834+ if (!$booted) {835835+ return 0 if ($in_bisect);836836+ fail "failed - never got a boot prompt." and return 0;837837+ }838838+839839+ return 1;840840+}841841+842842+sub install {843843+844844+ run_scp "$outputdir/$build_target", "$target_image" or845845+ dodie "failed to copy image";846846+847847+ my $install_mods = 0;848848+849849+ # should we process modules?850850+ $install_mods = 0;851851+ open(IN, "$output_config") or dodie("Can't read config file");852852+ while (<IN>) {853853+ if (/CONFIG_MODULES(=y)?/) {854854+ $install_mods = 1 if (defined($1));855855+ last;856856+ }857857+ }858858+ close(IN);859859+860860+ if (!$install_mods) {861861+ doprint "No modules needed\n";862862+ return;863863+ }864864+865865+ run_command "$make INSTALL_MOD_PATH=$tmpdir modules_install" or866866+ dodie "Failed to install modules";867867+868868+ my $modlib = "/lib/modules/$version";869869+ my $modtar = "ktest-mods.tar.bz2";870870+871871+ run_ssh "rm -rf $modlib" or872872+ dodie "failed to remove old mods: $modlib";873873+874874+ # would be nice if scp -r did not follow symbolic links875875+ run_command "cd $tmpdir && tar -cjf $modtar lib/modules/$version" or876876+ dodie "making tarball";877877+878878+ run_scp "$tmpdir/$modtar", "/tmp" or879879+ dodie "failed to copy modules";880880+881881+ unlink "$tmpdir/$modtar";882882+883883+ run_ssh "'(cd / && tar xf /tmp/$modtar)'" or884884+ dodie "failed to tar modules";885885+886886+ run_ssh "rm -f /tmp/$modtar";887887+888888+ return if (!defined($post_install));889889+890890+ my $cp_post_install = $post_install;891891+ $cp_post_install = s/\$KERNEL_VERSION/$version/g;892892+ run_command "$cp_post_install" or893893+ dodie "Failed to run post install";894894+}895895+896896+sub check_buildlog {897897+ my ($patch) = @_;898898+899899+ my @files = `git show $patch | diffstat -l`;900900+901901+ open(IN, "git show $patch |") or902902+ dodie "failed to show $patch";903903+ while (<IN>) {904904+ if (m,^--- a/(.*),) {905905+ chomp $1;906906+ $files[$#files] = $1;907907+ }908908+ }909909+ close(IN);910910+911911+ open(IN, $buildlog) or dodie "Can't open $buildlog";912912+ while (<IN>) {913913+ if (/^\s*(.*?):.*(warning|error)/) {914914+ my $err = $1;915915+ foreach my $file (@files) {916916+ my $fullpath = "$builddir/$file";917917+ if ($file eq $err || $fullpath eq $err) {918918+ fail "$file built with warnings" and return 0;919919+ }920920+ }921921+ }922922+ }923923+ close(IN);924924+925925+ return 1;926926+}927927+928928+sub build {929929+ my ($type) = @_;930930+ my $defconfig = "";931931+932932+ unlink $buildlog;933933+934934+ if ($type =~ /^useconfig:(.*)/) {935935+ run_command "cp $1 $output_config" or936936+ dodie "could not copy $1 to .config";937937+938938+ $type = "oldconfig";939939+ }940940+941941+ # old config can ask questions942942+ if ($type eq "oldconfig") {943943+ $type = "oldnoconfig";944944+945945+ # allow for empty configs946946+ run_command "touch $output_config";947947+948948+ run_command "mv $output_config $outputdir/config_temp" or949949+ dodie "moving .config";950950+951951+ if (!$noclean && !run_command "$make mrproper") {952952+ dodie "make mrproper";953953+ }954954+955955+ run_command "mv $outputdir/config_temp $output_config" or956956+ dodie "moving config_temp";957957+958958+ } elsif (!$noclean) {959959+ unlink "$output_config";960960+ run_command "$make mrproper" or961961+ dodie "make mrproper";962962+ }963963+964964+ # add something to distinguish this build965965+ open(OUT, "> $outputdir/localversion") or dodie("Can't make localversion file");966966+ print OUT "$localversion\n";967967+ close(OUT);968968+969969+ if (defined($minconfig)) {970970+ $defconfig = "KCONFIG_ALLCONFIG=$minconfig";971971+ }972972+973973+ run_command "$defconfig $make $type" or974974+ dodie "failed make config";975975+976976+ $redirect = "$buildlog";977977+ if (!run_command "$make $build_options") {978978+ undef $redirect;979979+ # bisect may need this to pass980980+ return 0 if ($in_bisect);981981+ fail "failed build" and return 0;982982+ }983983+ undef $redirect;984984+985985+ return 1;986986+}987987+988988+sub halt {989989+ if (!run_ssh "halt" or defined($power_off)) {990990+ if (defined($poweroff_after_halt)) {991991+ sleep $poweroff_after_halt;992992+ run_command "$power_off";993993+ }994994+ } else {995995+ # nope? the zap it!996996+ run_command "$power_off";997997+ }998998+}999999+10001000+sub success {10011001+ my ($i) = @_;10021002+10031003+ $successes++;10041004+10051005+ doprint "\n\n*******************************************\n";10061006+ doprint "*******************************************\n";10071007+ doprint "KTEST RESULT: TEST $i SUCCESS!!!! **\n";10081008+ doprint "*******************************************\n";10091009+ doprint "*******************************************\n";10101010+10111011+ if ($i != $opt{"NUM_TESTS"} && !do_not_reboot) {10121012+ doprint "Reboot and wait $sleep_time seconds\n";10131013+ reboot;10141014+ start_monitor;10151015+ wait_for_monitor $sleep_time;10161016+ end_monitor;10171017+ }10181018+}10191019+10201020+sub get_version {10211021+ # get the release name10221022+ doprint "$make kernelrelease ... ";10231023+ $version = `$make kernelrelease | tail -1`;10241024+ chomp($version);10251025+ doprint "$version\n";10261026+}10271027+10281028+sub child_run_test {10291029+ my $failed = 0;10301030+10311031+ # child should have no power10321032+ $reboot_on_error = 0;10331033+ $poweroff_on_error = 0;10341034+ $die_on_failure = 1;10351035+10361036+ run_command $run_test or $failed = 1;10371037+ exit $failed;10381038+}10391039+10401040+my $child_done;10411041+10421042+sub child_finished {10431043+ $child_done = 1;10441044+}10451045+10461046+sub do_run_test {10471047+ my $child_pid;10481048+ my $child_exit;10491049+ my $line;10501050+ my $full_line;10511051+ my $bug = 0;10521052+10531053+ wait_for_monitor 1;10541054+10551055+ doprint "run test $run_test\n";10561056+10571057+ $child_done = 0;10581058+10591059+ $SIG{CHLD} = qw(child_finished);10601060+10611061+ $child_pid = fork;10621062+10631063+ child_run_test if (!$child_pid);10641064+10651065+ $full_line = "";10661066+10671067+ do {10681068+ $line = wait_for_input($monitor_fp, 1);10691069+ if (defined($line)) {10701070+10711071+ # we are not guaranteed to get a full line10721072+ $full_line .= $line;10731073+10741074+ if ($full_line =~ /call trace:/i) {10751075+ $bug = 1;10761076+ }10771077+10781078+ if ($full_line =~ /Kernel panic -/) {10791079+ $bug = 1;10801080+ }10811081+10821082+ if ($line =~ /\n/) {10831083+ $full_line = "";10841084+ }10851085+ }10861086+ } while (!$child_done && !$bug);10871087+10881088+ if ($bug) {10891089+ doprint "Detected kernel crash!\n";10901090+ # kill the child with extreme prejudice10911091+ kill 9, $child_pid;10921092+ }10931093+10941094+ waitpid $child_pid, 0;10951095+ $child_exit = $?;10961096+10971097+ if ($bug || $child_exit) {10981098+ return 0 if $in_bisect;10991099+ fail "test failed" and return 0;11001100+ }11011101+ return 1;11021102+}11031103+11041104+sub run_git_bisect {11051105+ my ($command) = @_;11061106+11071107+ doprint "$command ... ";11081108+11091109+ my $output = `$command 2>&1`;11101110+ my $ret = $?;11111111+11121112+ logit $output;11131113+11141114+ if ($ret) {11151115+ doprint "FAILED\n";11161116+ dodie "Failed to git bisect";11171117+ }11181118+11191119+ doprint "SUCCESS\n";11201120+ if ($output =~ m/^(Bisecting: .*\(roughly \d+ steps?\))\s+\[([[:xdigit:]]+)\]/) {11211121+ doprint "$1 [$2]\n";11221122+ } elsif ($output =~ m/^([[:xdigit:]]+) is the first bad commit/) {11231123+ $bisect_bad = $1;11241124+ doprint "Found bad commit... $1\n";11251125+ return 0;11261126+ } else {11271127+ # we already logged it, just print it now.11281128+ print $output;11291129+ }11301130+11311131+ return 1;11321132+}11331133+11341134+# returns 1 on success, 0 on failure11351135+sub run_bisect_test {11361136+ my ($type, $buildtype) = @_;11371137+11381138+ my $failed = 0;11391139+ my $result;11401140+ my $output;11411141+ my $ret;11421142+11431143+ $in_bisect = 1;11441144+11451145+ build $buildtype or $failed = 1;11461146+11471147+ if ($type ne "build") {11481148+ dodie "Failed on build" if $failed;11491149+11501150+ # Now boot the box11511151+ get_grub_index;11521152+ get_version;11531153+ install;11541154+11551155+ start_monitor;11561156+ monitor or $failed = 1;11571157+11581158+ if ($type ne "boot") {11591159+ dodie "Failed on boot" if $failed;11601160+11611161+ do_run_test or $failed = 1;11621162+ }11631163+ end_monitor;11641164+ }11651165+11661166+ if ($failed) {11671167+ $result = 0;11681168+11691169+ # reboot the box to a good kernel11701170+ if ($type ne "build") {11711171+ doprint "Reboot and sleep $bisect_sleep_time seconds\n";11721172+ reboot;11731173+ start_monitor;11741174+ wait_for_monitor $bisect_sleep_time;11751175+ end_monitor;11761176+ }11771177+ } else {11781178+ $result = 1;11791179+ }11801180+ $in_bisect = 0;11811181+11821182+ return $result;11831183+}11841184+11851185+sub run_bisect {11861186+ my ($type) = @_;11871187+ my $buildtype = "oldconfig";11881188+11891189+ # We should have a minconfig to use?11901190+ if (defined($minconfig)) {11911191+ $buildtype = "useconfig:$minconfig";11921192+ }11931193+11941194+ my $ret = run_bisect_test $type, $buildtype;11951195+11961196+11971197+ # Are we looking for where it worked, not failed?11981198+ if ($reverse_bisect) {11991199+ $ret = !$ret;12001200+ }12011201+12021202+ if ($ret) {12031203+ return "good";12041204+ } else {12051205+ return "bad";12061206+ }12071207+}12081208+12091209+sub bisect {12101210+ my ($i) = @_;12111211+12121212+ my $result;12131213+12141214+ die "BISECT_GOOD[$i] not defined\n" if (!defined($opt{"BISECT_GOOD[$i]"}));12151215+ die "BISECT_BAD[$i] not defined\n" if (!defined($opt{"BISECT_BAD[$i]"}));12161216+ die "BISECT_TYPE[$i] not defined\n" if (!defined($opt{"BISECT_TYPE[$i]"}));12171217+12181218+ my $good = $opt{"BISECT_GOOD[$i]"};12191219+ my $bad = $opt{"BISECT_BAD[$i]"};12201220+ my $type = $opt{"BISECT_TYPE[$i]"};12211221+ my $start = $opt{"BISECT_START[$i]"};12221222+ my $replay = $opt{"BISECT_REPLAY[$i]"};12231223+12241224+ # convert to true sha1's12251225+ $good = get_sha1($good);12261226+ $bad = get_sha1($bad);12271227+12281228+ if (defined($opt{"BISECT_REVERSE[$i]"}) &&12291229+ $opt{"BISECT_REVERSE[$i]"} == 1) {12301230+ doprint "Performing a reverse bisect (bad is good, good is bad!)\n";12311231+ $reverse_bisect = 1;12321232+ } else {12331233+ $reverse_bisect = 0;12341234+ }12351235+12361236+ # Can't have a test without having a test to run12371237+ if ($type eq "test" && !defined($run_test)) {12381238+ $type = "boot";12391239+ }12401240+12411241+ my $check = $opt{"BISECT_CHECK[$i]"};12421242+ if (defined($check) && $check ne "0") {12431243+12441244+ # get current HEAD12451245+ my $head = get_sha1("HEAD");12461246+12471247+ if ($check ne "good") {12481248+ doprint "TESTING BISECT BAD [$bad]\n";12491249+ run_command "git checkout $bad" or12501250+ die "Failed to checkout $bad";12511251+12521252+ $result = run_bisect $type;12531253+12541254+ if ($result ne "bad") {12551255+ fail "Tested BISECT_BAD [$bad] and it succeeded" and return 0;12561256+ }12571257+ }12581258+12591259+ if ($check ne "bad") {12601260+ doprint "TESTING BISECT GOOD [$good]\n";12611261+ run_command "git checkout $good" or12621262+ die "Failed to checkout $good";12631263+12641264+ $result = run_bisect $type;12651265+12661266+ if ($result ne "good") {12671267+ fail "Tested BISECT_GOOD [$good] and it failed" and return 0;12681268+ }12691269+ }12701270+12711271+ # checkout where we started12721272+ run_command "git checkout $head" or12731273+ die "Failed to checkout $head";12741274+ }12751275+12761276+ run_command "git bisect start" or12771277+ dodie "could not start bisect";12781278+12791279+ run_command "git bisect good $good" or12801280+ dodie "could not set bisect good to $good";12811281+12821282+ run_git_bisect "git bisect bad $bad" or12831283+ dodie "could not set bisect bad to $bad";12841284+12851285+ if (defined($replay)) {12861286+ run_command "git bisect replay $replay" or12871287+ dodie "failed to run replay";12881288+ }12891289+12901290+ if (defined($start)) {12911291+ run_command "git checkout $start" or12921292+ dodie "failed to checkout $start";12931293+ }12941294+12951295+ my $test;12961296+ do {12971297+ $result = run_bisect $type;12981298+ $test = run_git_bisect "git bisect $result";12991299+ } while ($test);13001300+13011301+ run_command "git bisect log" or13021302+ dodie "could not capture git bisect log";13031303+13041304+ run_command "git bisect reset" or13051305+ dodie "could not reset git bisect";13061306+13071307+ doprint "Bad commit was [$bisect_bad]\n";13081308+13091309+ success $i;13101310+}13111311+13121312+my %config_ignore;13131313+my %config_set;13141314+13151315+my %config_list;13161316+my %null_config;13171317+13181318+my %dependency;13191319+13201320+sub process_config_ignore {13211321+ my ($config) = @_;13221322+13231323+ open (IN, $config)13241324+ or dodie "Failed to read $config";13251325+13261326+ while (<IN>) {13271327+ if (/^(.*?(CONFIG\S*)(=.*| is not set))/) {13281328+ $config_ignore{$2} = $1;13291329+ }13301330+ }13311331+13321332+ close(IN);13331333+}13341334+13351335+sub read_current_config {13361336+ my ($config_ref) = @_;13371337+13381338+ %{$config_ref} = ();13391339+ undef %{$config_ref};13401340+13411341+ my @key = keys %{$config_ref};13421342+ if ($#key >= 0) {13431343+ print "did not delete!\n";13441344+ exit;13451345+ }13461346+ open (IN, "$output_config");13471347+13481348+ while (<IN>) {13491349+ if (/^(CONFIG\S+)=(.*)/) {13501350+ ${$config_ref}{$1} = $2;13511351+ }13521352+ }13531353+ close(IN);13541354+}13551355+13561356+sub get_dependencies {13571357+ my ($config) = @_;13581358+13591359+ my $arr = $dependency{$config};13601360+ if (!defined($arr)) {13611361+ return ();13621362+ }13631363+13641364+ my @deps = @{$arr};13651365+13661366+ foreach my $dep (@{$arr}) {13671367+ print "ADD DEP $dep\n";13681368+ @deps = (@deps, get_dependencies $dep);13691369+ }13701370+13711371+ return @deps;13721372+}13731373+13741374+sub create_config {13751375+ my @configs = @_;13761376+13771377+ open(OUT, ">$output_config") or dodie "Can not write to $output_config";13781378+13791379+ foreach my $config (@configs) {13801380+ print OUT "$config_set{$config}\n";13811381+ my @deps = get_dependencies $config;13821382+ foreach my $dep (@deps) {13831383+ print OUT "$config_set{$dep}\n";13841384+ }13851385+ }13861386+13871387+ foreach my $config (keys %config_ignore) {13881388+ print OUT "$config_ignore{$config}\n";13891389+ }13901390+ close(OUT);13911391+13921392+# exit;13931393+ run_command "$make oldnoconfig" or13941394+ dodie "failed make config oldconfig";13951395+13961396+}13971397+13981398+sub compare_configs {13991399+ my (%a, %b) = @_;14001400+14011401+ foreach my $item (keys %a) {14021402+ if (!defined($b{$item})) {14031403+ print "diff $item\n";14041404+ return 1;14051405+ }14061406+ delete $b{$item};14071407+ }14081408+14091409+ my @keys = keys %b;14101410+ if ($#keys) {14111411+ print "diff2 $keys[0]\n";14121412+ }14131413+ return -1 if ($#keys >= 0);14141414+14151415+ return 0;14161416+}14171417+14181418+sub run_config_bisect_test {14191419+ my ($type) = @_;14201420+14211421+ return run_bisect_test $type, "oldconfig";14221422+}14231423+14241424+sub process_passed {14251425+ my (%configs) = @_;14261426+14271427+ doprint "These configs had no failure: (Enabling them for further compiles)\n";14281428+ # Passed! All these configs are part of a good compile.14291429+ # Add them to the min options.14301430+ foreach my $config (keys %configs) {14311431+ if (defined($config_list{$config})) {14321432+ doprint " removing $config\n";14331433+ $config_ignore{$config} = $config_list{$config};14341434+ delete $config_list{$config};14351435+ }14361436+ }14371437+ doprint "config copied to $outputdir/config_good\n";14381438+ run_command "cp -f $output_config $outputdir/config_good";14391439+}14401440+14411441+sub process_failed {14421442+ my ($config) = @_;14431443+14441444+ doprint "\n\n***************************************\n";14451445+ doprint "Found bad config: $config\n";14461446+ doprint "***************************************\n\n";14471447+}14481448+14491449+sub run_config_bisect {14501450+14511451+ my @start_list = keys %config_list;14521452+14531453+ if ($#start_list < 0) {14541454+ doprint "No more configs to test!!!\n";14551455+ return -1;14561456+ }14571457+14581458+ doprint "***** RUN TEST ***\n";14591459+ my $type = $opt{"CONFIG_BISECT_TYPE[$iteration]"};14601460+ my $ret;14611461+ my %current_config;14621462+14631463+ my $count = $#start_list + 1;14641464+ doprint " $count configs to test\n";14651465+14661466+ my $half = int($#start_list / 2);14671467+14681468+ do {14691469+ my @tophalf = @start_list[0 .. $half];14701470+14711471+ create_config @tophalf;14721472+ read_current_config \%current_config;14731473+14741474+ $count = $#tophalf + 1;14751475+ doprint "Testing $count configs\n";14761476+ my $found = 0;14771477+ # make sure we test something14781478+ foreach my $config (@tophalf) {14791479+ if (defined($current_config{$config})) {14801480+ logit " $config\n";14811481+ $found = 1;14821482+ }14831483+ }14841484+ if (!$found) {14851485+ # try the other half14861486+ doprint "Top half produced no set configs, trying bottom half\n";14871487+ @tophalf = @start_list[$half .. $#start_list];14881488+ create_config @tophalf;14891489+ read_current_config \%current_config;14901490+ foreach my $config (@tophalf) {14911491+ if (defined($current_config{$config})) {14921492+ logit " $config\n";14931493+ $found = 1;14941494+ }14951495+ }14961496+ if (!$found) {14971497+ doprint "Failed: Can't make new config with current configs\n";14981498+ foreach my $config (@start_list) {14991499+ doprint " CONFIG: $config\n";15001500+ }15011501+ return -1;15021502+ }15031503+ $count = $#tophalf + 1;15041504+ doprint "Testing $count configs\n";15051505+ }15061506+15071507+ $ret = run_config_bisect_test $type;15081508+15091509+ if ($ret) {15101510+ process_passed %current_config;15111511+ return 0;15121512+ }15131513+15141514+ doprint "This config had a failure.\n";15151515+ doprint "Removing these configs that were not set in this config:\n";15161516+ doprint "config copied to $outputdir/config_bad\n";15171517+ run_command "cp -f $output_config $outputdir/config_bad";15181518+15191519+ # A config exists in this group that was bad.15201520+ foreach my $config (keys %config_list) {15211521+ if (!defined($current_config{$config})) {15221522+ doprint " removing $config\n";15231523+ delete $config_list{$config};15241524+ }15251525+ }15261526+15271527+ @start_list = @tophalf;15281528+15291529+ if ($#start_list == 0) {15301530+ process_failed $start_list[0];15311531+ return 1;15321532+ }15331533+15341534+ # remove half the configs we are looking at and see if15351535+ # they are good.15361536+ $half = int($#start_list / 2);15371537+ } while ($half > 0);15381538+15391539+ # we found a single config, try it again15401540+ my @tophalf = @start_list[0 .. 0];15411541+15421542+ $ret = run_config_bisect_test $type;15431543+ if ($ret) {15441544+ process_passed %current_config;15451545+ return 0;15461546+ }15471547+15481548+ process_failed $start_list[0];15491549+ return 1;15501550+}15511551+15521552+sub config_bisect {15531553+ my ($i) = @_;15541554+15551555+ my $start_config = $opt{"CONFIG_BISECT[$i]"};15561556+15571557+ my $tmpconfig = "$tmpdir/use_config";15581558+15591559+ # Make the file with the bad config and the min config15601560+ if (defined($minconfig)) {15611561+ # read the min config for things to ignore15621562+ run_command "cp $minconfig $tmpconfig" or15631563+ dodie "failed to copy $minconfig to $tmpconfig";15641564+ } else {15651565+ unlink $tmpconfig;15661566+ }15671567+15681568+ # Add other configs15691569+ if (defined($addconfig)) {15701570+ run_command "cat $addconfig >> $tmpconfig" or15711571+ dodie "failed to append $addconfig";15721572+ }15731573+15741574+ my $defconfig = "";15751575+ if (-f $tmpconfig) {15761576+ $defconfig = "KCONFIG_ALLCONFIG=$tmpconfig";15771577+ process_config_ignore $tmpconfig;15781578+ }15791579+15801580+ # now process the start config15811581+ run_command "cp $start_config $output_config" or15821582+ dodie "failed to copy $start_config to $output_config";15831583+15841584+ # read directly what we want to check15851585+ my %config_check;15861586+ open (IN, $output_config)15871587+ or dodie "faied to open $output_config";15881588+15891589+ while (<IN>) {15901590+ if (/^((CONFIG\S*)=.*)/) {15911591+ $config_check{$2} = $1;15921592+ }15931593+ }15941594+ close(IN);15951595+15961596+ # Now run oldconfig with the minconfig (and addconfigs)15971597+ run_command "$defconfig $make oldnoconfig" or15981598+ dodie "failed make config oldconfig";15991599+16001600+ # check to see what we lost (or gained)16011601+ open (IN, $output_config)16021602+ or dodie "Failed to read $start_config";16031603+16041604+ my %removed_configs;16051605+ my %added_configs;16061606+16071607+ while (<IN>) {16081608+ if (/^((CONFIG\S*)=.*)/) {16091609+ # save off all options16101610+ $config_set{$2} = $1;16111611+ if (defined($config_check{$2})) {16121612+ if (defined($config_ignore{$2})) {16131613+ $removed_configs{$2} = $1;16141614+ } else {16151615+ $config_list{$2} = $1;16161616+ }16171617+ } elsif (!defined($config_ignore{$2})) {16181618+ $added_configs{$2} = $1;16191619+ $config_list{$2} = $1;16201620+ }16211621+ }16221622+ }16231623+ close(IN);16241624+16251625+ my @confs = keys %removed_configs;16261626+ if ($#confs >= 0) {16271627+ doprint "Configs overridden by default configs and removed from check:\n";16281628+ foreach my $config (@confs) {16291629+ doprint " $config\n";16301630+ }16311631+ }16321632+ @confs = keys %added_configs;16331633+ if ($#confs >= 0) {16341634+ doprint "Configs appearing in make oldconfig and added:\n";16351635+ foreach my $config (@confs) {16361636+ doprint " $config\n";16371637+ }16381638+ }16391639+16401640+ my %config_test;16411641+ my $once = 0;16421642+16431643+ # Sometimes kconfig does weird things. We must make sure16441644+ # that the config we autocreate has everything we need16451645+ # to test, otherwise we may miss testing configs, or16461646+ # may not be able to create a new config.16471647+ # Here we create a config with everything set.16481648+ create_config (keys %config_list);16491649+ read_current_config \%config_test;16501650+ foreach my $config (keys %config_list) {16511651+ if (!defined($config_test{$config})) {16521652+ if (!$once) {16531653+ $once = 1;16541654+ doprint "Configs not produced by kconfig (will not be checked):\n";16551655+ }16561656+ doprint " $config\n";16571657+ delete $config_list{$config};16581658+ }16591659+ }16601660+ my $ret;16611661+ do {16621662+ $ret = run_config_bisect;16631663+ } while (!$ret);16641664+16651665+ return $ret if ($ret < 0);16661666+16671667+ success $i;16681668+}16691669+16701670+sub patchcheck {16711671+ my ($i) = @_;16721672+16731673+ die "PATCHCHECK_START[$i] not defined\n"16741674+ if (!defined($opt{"PATCHCHECK_START[$i]"}));16751675+ die "PATCHCHECK_TYPE[$i] not defined\n"16761676+ if (!defined($opt{"PATCHCHECK_TYPE[$i]"}));16771677+16781678+ my $start = $opt{"PATCHCHECK_START[$i]"};16791679+16801680+ my $end = "HEAD";16811681+ if (defined($opt{"PATCHCHECK_END[$i]"})) {16821682+ $end = $opt{"PATCHCHECK_END[$i]"};16831683+ }16841684+16851685+ # Get the true sha1's since we can use things like HEAD~316861686+ $start = get_sha1($start);16871687+ $end = get_sha1($end);16881688+16891689+ my $type = $opt{"PATCHCHECK_TYPE[$i]"};16901690+16911691+ # Can't have a test without having a test to run16921692+ if ($type eq "test" && !defined($run_test)) {16931693+ $type = "boot";16941694+ }16951695+16961696+ open (IN, "git log --pretty=oneline $end|") or16971697+ dodie "could not get git list";16981698+16991699+ my @list;17001700+17011701+ while (<IN>) {17021702+ chomp;17031703+ $list[$#list+1] = $_;17041704+ last if (/^$start/);17051705+ }17061706+ close(IN);17071707+17081708+ if ($list[$#list] !~ /^$start/) {17091709+ fail "SHA1 $start not found";17101710+ }17111711+17121712+ # go backwards in the list17131713+ @list = reverse @list;17141714+17151715+ my $save_clean = $noclean;17161716+17171717+ $in_patchcheck = 1;17181718+ foreach my $item (@list) {17191719+ my $sha1 = $item;17201720+ $sha1 =~ s/^([[:xdigit:]]+).*/$1/;17211721+17221722+ doprint "\nProcessing commit $item\n\n";17231723+17241724+ run_command "git checkout $sha1" or17251725+ die "Failed to checkout $sha1";17261726+17271727+ # only clean on the first and last patch17281728+ if ($item eq $list[0] ||17291729+ $item eq $list[$#list]) {17301730+ $noclean = $save_clean;17311731+ } else {17321732+ $noclean = 1;17331733+ }17341734+17351735+ if (defined($minconfig)) {17361736+ build "useconfig:$minconfig" or return 0;17371737+ } else {17381738+ # ?? no config to use?17391739+ build "oldconfig" or return 0;17401740+ }17411741+17421742+ check_buildlog $sha1 or return 0;17431743+17441744+ next if ($type eq "build");17451745+17461746+ get_grub_index;17471747+ get_version;17481748+ install;17491749+17501750+ my $failed = 0;17511751+17521752+ start_monitor;17531753+ monitor or $failed = 1;17541754+17551755+ if (!$failed && $type ne "boot"){17561756+ do_run_test or $failed = 1;17571757+ }17581758+ end_monitor;17591759+ return 0 if ($failed);17601760+17611761+ }17621762+ $in_patchcheck = 0;17631763+ success $i;17641764+17651765+ return 1;17661766+}17671767+17681768+$#ARGV < 1 or die "ktest.pl version: $VERSION\n usage: ktest.pl config-file\n";17691769+17701770+if ($#ARGV == 0) {17711771+ $ktest_config = $ARGV[0];17721772+ if (! -f $ktest_config) {17731773+ print "$ktest_config does not exist.\n";17741774+ my $ans;17751775+ for (;;) {17761776+ print "Create it? [Y/n] ";17771777+ $ans = <STDIN>;17781778+ chomp $ans;17791779+ if ($ans =~ /^\s*$/) {17801780+ $ans = "y";17811781+ }17821782+ last if ($ans =~ /^y$/i || $ans =~ /^n$/i);17831783+ print "Please answer either 'y' or 'n'.\n";17841784+ }17851785+ if ($ans !~ /^y$/i) {17861786+ exit 0;17871787+ }17881788+ }17891789+} else {17901790+ $ktest_config = "ktest.conf";17911791+}17921792+17931793+if (! -f $ktest_config) {17941794+ open(OUT, ">$ktest_config") or die "Can not create $ktest_config";17951795+ print OUT << "EOF"17961796+# Generated by ktest.pl17971797+#17981798+# Define each test with TEST_START17991799+# The config options below it will override the defaults18001800+TEST_START18011801+18021802+DEFAULTS18031803+EOF18041804+;18051805+ close(OUT);18061806+}18071807+read_config $ktest_config;18081808+18091809+# Append any configs entered in manually to the config file.18101810+my @new_configs = keys %entered_configs;18111811+if ($#new_configs >= 0) {18121812+ print "\nAppending entered in configs to $ktest_config\n";18131813+ open(OUT, ">>$ktest_config") or die "Can not append to $ktest_config";18141814+ foreach my $config (@new_configs) {18151815+ print OUT "$config = $entered_configs{$config}\n";18161816+ $opt{$config} = $entered_configs{$config};18171817+ }18181818+}18191819+18201820+if ($opt{"CLEAR_LOG"} && defined($opt{"LOG_FILE"})) {18211821+ unlink $opt{"LOG_FILE"};18221822+}18231823+18241824+doprint "\n\nSTARTING AUTOMATED TESTS\n\n";18251825+18261826+for (my $i = 0, my $repeat = 1; $i <= $opt{"NUM_TESTS"}; $i += $repeat) {18271827+18281828+ if (!$i) {18291829+ doprint "DEFAULT OPTIONS:\n";18301830+ } else {18311831+ doprint "\nTEST $i OPTIONS";18321832+ if (defined($repeat_tests{$i})) {18331833+ $repeat = $repeat_tests{$i};18341834+ doprint " ITERATE $repeat";18351835+ }18361836+ doprint "\n";18371837+ }18381838+18391839+ foreach my $option (sort keys %opt) {18401840+18411841+ if ($option =~ /\[(\d+)\]$/) {18421842+ next if ($i != $1);18431843+ } else {18441844+ next if ($i);18451845+ }18461846+18471847+ doprint "$option = $opt{$option}\n";18481848+ }18491849+}18501850+18511851+sub set_test_option {18521852+ my ($name, $i) = @_;18531853+18541854+ my $option = "$name\[$i\]";18551855+18561856+ if (defined($opt{$option})) {18571857+ return $opt{$option};18581858+ }18591859+18601860+ foreach my $test (keys %repeat_tests) {18611861+ if ($i >= $test &&18621862+ $i < $test + $repeat_tests{$test}) {18631863+ $option = "$name\[$test\]";18641864+ if (defined($opt{$option})) {18651865+ return $opt{$option};18661866+ }18671867+ }18681868+ }18691869+18701870+ if (defined($opt{$name})) {18711871+ return $opt{$name};18721872+ }18731873+18741874+ return undef;18751875+}18761876+18771877+# First we need to do is the builds18781878+for (my $i = 1; $i <= $opt{"NUM_TESTS"}; $i++) {18791879+18801880+ $iteration = $i;18811881+18821882+ my $makecmd = set_test_option("MAKE_CMD", $i);18831883+18841884+ $machine = set_test_option("MACHINE", $i);18851885+ $ssh_user = set_test_option("SSH_USER", $i);18861886+ $tmpdir = set_test_option("TMP_DIR", $i);18871887+ $outputdir = set_test_option("OUTPUT_DIR", $i);18881888+ $builddir = set_test_option("BUILD_DIR", $i);18891889+ $test_type = set_test_option("TEST_TYPE", $i);18901890+ $build_type = set_test_option("BUILD_TYPE", $i);18911891+ $build_options = set_test_option("BUILD_OPTIONS", $i);18921892+ $power_cycle = set_test_option("POWER_CYCLE", $i);18931893+ $reboot = set_test_option("REBOOT", $i);18941894+ $noclean = set_test_option("BUILD_NOCLEAN", $i);18951895+ $minconfig = set_test_option("MIN_CONFIG", $i);18961896+ $run_test = set_test_option("TEST", $i);18971897+ $addconfig = set_test_option("ADD_CONFIG", $i);18981898+ $reboot_type = set_test_option("REBOOT_TYPE", $i);18991899+ $grub_menu = set_test_option("GRUB_MENU", $i);19001900+ $post_install = set_test_option("POST_INSTALL", $i);19011901+ $reboot_script = set_test_option("REBOOT_SCRIPT", $i);19021902+ $reboot_on_error = set_test_option("REBOOT_ON_ERROR", $i);19031903+ $poweroff_on_error = set_test_option("POWEROFF_ON_ERROR", $i);19041904+ $die_on_failure = set_test_option("DIE_ON_FAILURE", $i);19051905+ $power_off = set_test_option("POWER_OFF", $i);19061906+ $powercycle_after_reboot = set_test_option("POWERCYCLE_AFTER_REBOOT", $i);19071907+ $poweroff_after_halt = set_test_option("POWEROFF_AFTER_HALT", $i);19081908+ $sleep_time = set_test_option("SLEEP_TIME", $i);19091909+ $bisect_sleep_time = set_test_option("BISECT_SLEEP_TIME", $i);19101910+ $store_failures = set_test_option("STORE_FAILURES", $i);19111911+ $timeout = set_test_option("TIMEOUT", $i);19121912+ $booted_timeout = set_test_option("BOOTED_TIMEOUT", $i);19131913+ $console = set_test_option("CONSOLE", $i);19141914+ $success_line = set_test_option("SUCCESS_LINE", $i);19151915+ $stop_after_success = set_test_option("STOP_AFTER_SUCCESS", $i);19161916+ $stop_after_failure = set_test_option("STOP_AFTER_FAILURE", $i);19171917+ $build_target = set_test_option("BUILD_TARGET", $i);19181918+ $ssh_exec = set_test_option("SSH_EXEC", $i);19191919+ $scp_to_target = set_test_option("SCP_TO_TARGET", $i);19201920+ $target_image = set_test_option("TARGET_IMAGE", $i);19211921+ $localversion = set_test_option("LOCALVERSION", $i);19221922+19231923+ chdir $builddir || die "can't change directory to $builddir";19241924+19251925+ if (!-d $tmpdir) {19261926+ mkpath($tmpdir) or19271927+ die "can't create $tmpdir";19281928+ }19291929+19301930+ $ENV{"SSH_USER"} = $ssh_user;19311931+ $ENV{"MACHINE"} = $machine;19321932+19331933+ $target = "$ssh_user\@$machine";19341934+19351935+ $buildlog = "$tmpdir/buildlog-$machine";19361936+ $dmesg = "$tmpdir/dmesg-$machine";19371937+ $make = "$makecmd O=$outputdir";19381938+ $output_config = "$outputdir/.config";19391939+19401940+ if ($reboot_type eq "grub") {19411941+ dodie "GRUB_MENU not defined" if (!defined($grub_menu));19421942+ } elsif (!defined($reboot_script)) {19431943+ dodie "REBOOT_SCRIPT not defined"19441944+ }19451945+19461946+ my $run_type = $build_type;19471947+ if ($test_type eq "patchcheck") {19481948+ $run_type = $opt{"PATCHCHECK_TYPE[$i]"};19491949+ } elsif ($test_type eq "bisect") {19501950+ $run_type = $opt{"BISECT_TYPE[$i]"};19511951+ } elsif ($test_type eq "config_bisect") {19521952+ $run_type = $opt{"CONFIG_BISECT_TYPE[$i]"};19531953+ }19541954+19551955+ # mistake in config file?19561956+ if (!defined($run_type)) {19571957+ $run_type = "ERROR";19581958+ }19591959+19601960+ doprint "\n\n";19611961+ doprint "RUNNING TEST $i of $opt{NUM_TESTS} with option $test_type $run_type\n\n";19621962+19631963+ unlink $dmesg;19641964+ unlink $buildlog;19651965+19661966+ if (!defined($minconfig)) {19671967+ $minconfig = $addconfig;19681968+19691969+ } elsif (defined($addconfig)) {19701970+ run_command "cat $addconfig $minconfig > $tmpdir/add_config" or19711971+ dodie "Failed to create temp config";19721972+ $minconfig = "$tmpdir/add_config";19731973+ }19741974+19751975+ my $checkout = $opt{"CHECKOUT[$i]"};19761976+ if (defined($checkout)) {19771977+ run_command "git checkout $checkout" or19781978+ die "failed to checkout $checkout";19791979+ }19801980+19811981+ if ($test_type eq "bisect") {19821982+ bisect $i;19831983+ next;19841984+ } elsif ($test_type eq "config_bisect") {19851985+ config_bisect $i;19861986+ next;19871987+ } elsif ($test_type eq "patchcheck") {19881988+ patchcheck $i;19891989+ next;19901990+ }19911991+19921992+ if ($build_type ne "nobuild") {19931993+ build $build_type or next;19941994+ }19951995+19961996+ if ($test_type ne "build") {19971997+ get_grub_index;19981998+ get_version;19991999+ install;20002000+20012001+ my $failed = 0;20022002+ start_monitor;20032003+ monitor or $failed = 1;;20042004+20052005+ if (!$failed && $test_type ne "boot" && defined($run_test)) {20062006+ do_run_test or $failed = 1;20072007+ }20082008+ end_monitor;20092009+ next if ($failed);20102010+ }20112011+20122012+ success $i;20132013+}20142014+20152015+if ($opt{"POWEROFF_ON_SUCCESS"}) {20162016+ halt;20172017+} elsif ($opt{"REBOOT_ON_SUCCESS"} && !do_not_reboot) {20182018+ reboot;20192019+}20202020+20212021+doprint "\n $successes of $opt{NUM_TESTS} tests were successful\n\n";20222022+20232023+exit 0;
+622
tools/testing/ktest/sample.conf
···11+#22+# Config file for ktest.pl33+#44+# Note, all paths must be absolute55+#66+77+# Options set in the beginning of the file are considered to be88+# default options. These options can be overriden by test specific99+# options, with the following exceptions:1010+#1111+# LOG_FILE1212+# CLEAR_LOG1313+# POWEROFF_ON_SUCCESS1414+# REBOOT_ON_SUCCESS1515+#1616+# Test specific options are set after the label:1717+#1818+# TEST_START1919+#2020+# The options after a TEST_START label are specific to that test.2121+# Each TEST_START label will set up a new test. If you want to2222+# perform a test more than once, you can add the ITERATE label2323+# to it followed by the number of times you want that test2424+# to iterate. If the ITERATE is left off, the test will only2525+# be performed once.2626+#2727+# TEST_START ITERATE 102828+#2929+# You can skip a test by adding SKIP (before or after the ITERATE3030+# and number)3131+#3232+# TEST_START SKIP3333+#3434+# TEST_START SKIP ITERATE 103535+#3636+# TEST_START ITERATE 10 SKIP3737+#3838+# The SKIP label causes the options and the test itself to be ignored.3939+# This is useful to set up several different tests in one config file, and4040+# only enabling the ones you want to use for a current test run.4141+#4242+# You can add default options anywhere in the file as well4343+# with the DEFAULTS tag. This allows you to have default options4444+# after the test options to keep the test options at the top4545+# of the file. You can even place the DEFAULTS tag between4646+# test cases (but not in the middle of a single test case)4747+#4848+# TEST_START4949+# MIN_CONFIG = /home/test/config-test15050+#5151+# DEFAULTS5252+# MIN_CONFIG = /home/test/config-default5353+#5454+# TEST_START ITERATE 105555+#5656+# The above will run the first test with MIN_CONFIG set to5757+# /home/test/config-test-1. Then 10 tests will be executed5858+# with MIN_CONFIG with /home/test/config-default.5959+#6060+# You can also disable defaults with the SKIP option6161+#6262+# DEFAULTS SKIP6363+# MIN_CONFIG = /home/test/config-use-sometimes6464+#6565+# DEFAULTS6666+# MIN_CONFIG = /home/test/config-most-times6767+#6868+# The above will ignore the first MIN_CONFIG. If you want to6969+# use the first MIN_CONFIG, remove the SKIP from the first7070+# DEFAULTS tag and add it to the second. Be careful, options7171+# may only be declared once per test or default. If you have7272+# the same option name under the same test or as default7373+# ktest will fail to execute, and no tests will run.7474+#7575+7676+7777+#### Mandatory Default Options ####7878+7979+# These options must be in the default section, although most8080+# may be overridden by test options.8181+8282+# The machine hostname that you will test8383+#MACHINE = target8484+8585+# The box is expected to have ssh on normal bootup, provide the user8686+# (most likely root, since you need privileged operations)8787+#SSH_USER = root8888+8989+# The directory that contains the Linux source code9090+#BUILD_DIR = /home/test/linux.git9191+9292+# The directory that the objects will be built9393+# (can not be same as BUILD_DIR)9494+#OUTPUT_DIR = /home/test/build/target9595+9696+# The location of the compiled file to copy to the target9797+# (relative to OUTPUT_DIR)9898+#BUILD_TARGET = arch/x86/boot/bzImage9999+100100+# The place to put your image on the test machine101101+#TARGET_IMAGE = /boot/vmlinuz-test102102+103103+# A script or command to reboot the box104104+#105105+# Here is a digital loggers power switch example106106+#POWER_CYCLE = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin@power/outlet?5=CCL'107107+#108108+# Here is an example to reboot a virtual box on the current host109109+# with the name "Guest".110110+#POWER_CYCLE = virsh destroy Guest; sleep 5; virsh start Guest111111+112112+# The script or command that reads the console113113+#114114+# If you use ttywatch server, something like the following would work.115115+#CONSOLE = nc -d localhost 3001116116+#117117+# For a virtual machine with guest name "Guest".118118+#CONSOLE = virsh console Guest119119+120120+# Required version ending to differentiate the test121121+# from other linux builds on the system.122122+#LOCALVERSION = -test123123+124124+# The grub title name for the test kernel to boot125125+# (Only mandatory if REBOOT_TYPE = grub)126126+#127127+# Note, ktest.pl will not update the grub menu.lst, you need to128128+# manually add an option for the test. ktest.pl will search129129+# the grub menu.lst for this option to find what kernel to130130+# reboot into.131131+#132132+# For example, if in the /boot/grub/menu.lst the test kernel title has:133133+# title Test Kernel134134+# kernel vmlinuz-test135135+#GRUB_MENU = Test Kernel136136+137137+# A script to reboot the target into the test kernel138138+# (Only mandatory if REBOOT_TYPE = script)139139+#REBOOT_SCRIPT =140140+141141+#### Optional Config Options (all have defaults) ####142142+143143+# Start a test setup. If you leave this off, all options144144+# will be default and the test will run once.145145+# This is a label and not really an option (it takes no value).146146+# You can append ITERATE and a number after it to iterate the147147+# test a number of times, or SKIP to ignore this test.148148+#149149+#TEST_START150150+#TEST_START ITERATE 5151151+#TEST_START SKIP152152+153153+# Have the following options as default again. Used after tests154154+# have already been defined by TEST_START. Optionally, you can155155+# just define all default options before the first TEST_START156156+# and you do not need this option.157157+#158158+# This is a label and not really an option (it takes no value).159159+# You can append SKIP to this label and the options within this160160+# section will be ignored.161161+#162162+# DEFAULTS163163+# DEFAULTS SKIP164164+165165+# The default test type (default test)166166+# The test types may be:167167+# build - only build the kernel, do nothing else168168+# boot - build and boot the kernel169169+# test - build, boot and if TEST is set, run the test script170170+# (If TEST is not set, it defaults back to boot)171171+# bisect - Perform a bisect on the kernel (see BISECT_TYPE below)172172+# patchcheck - Do a test on a series of commits in git (see PATCHCHECK below)173173+#TEST_TYPE = test174174+175175+# Test to run if there is a successful boot and TEST_TYPE is test.176176+# Must exit with 0 on success and non zero on error177177+# default (undefined)178178+#TEST = ssh user@machine /root/run_test179179+180180+# The build type is any make config type or special command181181+# (default randconfig)182182+# nobuild - skip the clean and build step183183+# useconfig:/path/to/config - use the given config and run184184+# oldconfig on it.185185+# This option is ignored if TEST_TYPE is patchcheck or bisect186186+#BUILD_TYPE = randconfig187187+188188+# The make command (default make)189189+# If you are building a 32bit x86 on a 64 bit host190190+#MAKE_CMD = CC=i386-gcc AS=i386-as make ARCH=i386191191+192192+# Any build options for the make of the kernel (not for other makes, like configs)193193+# (default "")194194+#BUILD_OPTIONS = -j20195195+196196+# If you need an initrd, you can add a script or code here to install197197+# it. The environment variable KERNEL_VERSION will be set to the198198+# kernel version that is used. Remember to add the initrd line199199+# to your grub menu.lst file.200200+#201201+# Here's a couple of examples to use:202202+#POST_INSTALL = ssh user@target /sbin/mkinitrd --allow-missing -f /boot/initramfs-test.img $KERNEL_VERSION203203+#204204+# or on some systems:205205+#POST_INSTALL = ssh user@target /sbin/dracut -f /boot/initramfs-test.img $KERNEL_VERSION206206+207207+# Way to reboot the box to the test kernel.208208+# Only valid options so far are "grub" and "script"209209+# (default grub)210210+# If you specify grub, it will assume grub version 1211211+# and will search in /boot/grub/menu.lst for the title $GRUB_MENU212212+# and select that target to reboot to the kernel. If this is not213213+# your setup, then specify "script" and have a command or script214214+# specified in REBOOT_SCRIPT to boot to the target.215215+#216216+# The entry in /boot/grub/menu.lst must be entered in manually.217217+# The test will not modify that file.218218+#REBOOT_TYPE = grub219219+220220+# The min config that is needed to build for the machine221221+# A nice way to create this is with the following:222222+#223223+# $ ssh target224224+# $ lsmod > mymods225225+# $ scp mymods host:/tmp226226+# $ exit227227+# $ cd linux.git228228+# $ rm .config229229+# $ make LSMOD=mymods localyesconfig230230+# $ grep '^CONFIG' .config > /home/test/config-min231231+#232232+# If you want even less configs:233233+#234234+# log in directly to target (do not ssh)235235+#236236+# $ su237237+# # lsmod | cut -d' ' -f1 | xargs rmmod238238+#239239+# repeat the above several times240240+#241241+# # lsmod > mymods242242+# # reboot243243+#244244+# May need to reboot to get your network back to copy the mymods245245+# to the host, and then remove the previous .config and run the246246+# localyesconfig again. The CONFIG_MIN generated like this will247247+# not guarantee network activity to the box so the TEST_TYPE of248248+# test may fail.249249+#250250+# You might also want to set:251251+# CONFIG_CMDLINE="<your options here>"252252+# randconfig may set the above and override your real command253253+# line options.254254+# (default undefined)255255+#MIN_CONFIG = /home/test/config-min256256+257257+# Sometimes there's options that just break the boot and258258+# you do not care about. Here are a few:259259+# # CONFIG_STAGING is not set260260+# Staging drivers are horrible, and can break the build.261261+# # CONFIG_SCSI_DEBUG is not set262262+# SCSI_DEBUG may change your root partition263263+# # CONFIG_KGDB_SERIAL_CONSOLE is not set264264+# KGDB may cause oops waiting for a connection that's not there.265265+# This option points to the file containing config options that will be prepended266266+# to the MIN_CONFIG (or be the MIN_CONFIG if it is not set)267267+#268268+# Note, config options in MIN_CONFIG will override these options.269269+#270270+# (default undefined)271271+#ADD_CONFIG = /home/test/config-broken272272+273273+# The location on the host where to write temp files274274+# (default /tmp/ktest)275275+#TMP_DIR = /tmp/ktest276276+277277+# Optional log file to write the status (recommended)278278+# Note, this is a DEFAULT section only option.279279+# (default undefined)280280+#LOG_FILE = /home/test/logfiles/target.log281281+282282+# Remove old logfile if it exists before starting all tests.283283+# Note, this is a DEFAULT section only option.284284+# (default 0)285285+#CLEAR_LOG = 0286286+287287+# Line to define a successful boot up in console output.288288+# This is what the line contains, not the entire line. If you need289289+# the entire line to match, then use regural expression syntax like:290290+# (do not add any quotes around it)291291+#292292+# SUCCESS_LINE = ^MyBox Login:$293293+#294294+# (default "login:")295295+#SUCCESS_LINE = login:296296+297297+# In case the console constantly fills the screen, having298298+# a specified time to stop the test after success is recommended.299299+# (in seconds)300300+# (default 10)301301+#STOP_AFTER_SUCCESS = 10302302+303303+# In case the console constantly fills the screen, having304304+# a specified time to stop the test after failure is recommended.305305+# (in seconds)306306+# (default 60)307307+#STOP_AFTER_FAILURE = 60308308+309309+# Stop testing if a build fails. If set, the script will end if310310+# a failure is detected, otherwise it will save off the .config,311311+# dmesg and bootlog in a directory called312312+# MACHINE-TEST_TYPE_BUILD_TYPE-fail-yyyymmddhhmmss313313+# if the STORE_FAILURES directory is set.314314+# (default 1)315315+# Note, even if this is set to zero, there are some errors that still316316+# stop the tests.317317+#DIE_ON_FAILURE = 1318318+319319+# Directory to store failure directories on failure. If this is not320320+# set, DIE_ON_FAILURE=0 will not save off the .config, dmesg and321321+# bootlog. This option is ignored if DIE_ON_FAILURE is not set.322322+# (default undefined)323323+#STORE_FAILURES = /home/test/failures324324+325325+# Build without doing a make mrproper, or removing .config326326+# (default 0)327327+#BUILD_NOCLEAN = 0328328+329329+# As the test reads the console, after it hits the SUCCESS_LINE330330+# the time it waits for the monitor to settle down between reads331331+# can usually be lowered.332332+# (in seconds) (default 1)333333+#BOOTED_TIMEOUT = 1334334+335335+# The timeout in seconds when we consider the box hung after336336+# the console stop producing output. Be sure to leave enough337337+# time here to get pass a reboot. Some machines may not produce338338+# any console output for a long time during a reboot. You do339339+# not want the test to fail just because the system was in340340+# the process of rebooting to the test kernel.341341+# (default 120)342342+#TIMEOUT = 120343343+344344+# In between tests, a reboot of the box may occur, and this345345+# is the time to wait for the console after it stops producing346346+# output. Some machines may not produce a large lag on reboot347347+# so this should accommodate it.348348+# The difference between this and TIMEOUT, is that TIMEOUT happens349349+# when rebooting to the test kernel. This sleep time happens350350+# after a test has completed and we are about to start running351351+# another test. If a reboot to the reliable kernel happens,352352+# we wait SLEEP_TIME for the console to stop producing output353353+# before starting the next test.354354+# (default 60)355355+#SLEEP_TIME = 60356356+357357+# The time in between bisects to sleep (in seconds)358358+# (default 60)359359+#BISECT_SLEEP_TIME = 60360360+361361+# Reboot the target box on error (default 0)362362+#REBOOT_ON_ERROR = 0363363+364364+# Power off the target on error (ignored if REBOOT_ON_ERROR is set)365365+# Note, this is a DEFAULT section only option.366366+# (default 0)367367+#POWEROFF_ON_ERROR = 0368368+369369+# Power off the target after all tests have completed successfully370370+# Note, this is a DEFAULT section only option.371371+# (default 0)372372+#POWEROFF_ON_SUCCESS = 0373373+374374+# Reboot the target after all test completed successfully (default 1)375375+# (ignored if POWEROFF_ON_SUCCESS is set)376376+#REBOOT_ON_SUCCESS = 1377377+378378+# In case there are isses with rebooting, you can specify this379379+# to always powercycle after this amount of time after calling380380+# reboot.381381+# Note, POWERCYCLE_AFTER_REBOOT = 0 does NOT disable it. It just382382+# makes it powercycle immediately after rebooting. Do not define383383+# it if you do not want it.384384+# (default undefined)385385+#POWERCYCLE_AFTER_REBOOT = 5386386+387387+# In case there's isses with halting, you can specify this388388+# to always poweroff after this amount of time after calling389389+# halt.390390+# Note, POWEROFF_AFTER_HALT = 0 does NOT disable it. It just391391+# makes it poweroff immediately after halting. Do not define392392+# it if you do not want it.393393+# (default undefined)394394+#POWEROFF_AFTER_HALT = 20395395+396396+# A script or command to power off the box (default undefined)397397+# Needed for POWEROFF_ON_ERROR and SUCCESS398398+#399399+# Example for digital loggers power switch:400400+#POWER_OFF = wget --no-proxy -O /dev/null -q --auth-no-challenge 'http://admin:admin@power/outlet?5=OFF'401401+#402402+# Example for a virtual guest call "Guest".403403+#POWER_OFF = virsh destroy Guest404404+405405+# The way to execute a command on the target406406+# (default ssh $SSH_USER@$MACHINE $SSH_COMMAND";)407407+# The variables SSH_USER, MACHINE and SSH_COMMAND are defined408408+#SSH_EXEC = ssh $SSH_USER@$MACHINE $SSH_COMMAND";409409+410410+# The way to copy a file to the target411411+# (default scp $SRC_FILE $SSH_USER@$MACHINE:$DST_FILE)412412+# The variables SSH_USER, MACHINE, SRC_FILE and DST_FILE are defined.413413+#SCP_TO_TARGET = scp $SRC_FILE $SSH_USER@$MACHINE:$DST_FILE414414+415415+# The nice way to reboot the target416416+# (default ssh $SSH_USER@$MACHINE reboot)417417+# The variables SSH_USER and MACHINE are defined.418418+#REBOOT = ssh $SSH_USER@$MACHINE reboot419419+420420+#### Per test run options ####421421+# The following options are only allowed in TEST_START sections.422422+# They are ignored in the DEFAULTS sections.423423+#424424+# All of these are optional and undefined by default, although425425+# some of these options are required for TEST_TYPE of patchcheck426426+# and bisect.427427+#428428+#429429+# CHECKOUT = branch430430+#431431+# If the BUILD_DIR is a git repository, then you can set this option432432+# to checkout the given branch before running the TEST. If you433433+# specify this for the first run, that branch will be used for434434+# all preceding tests until a new CHECKOUT is set.435435+#436436+#437437+#438438+# For TEST_TYPE = patchcheck439439+#440440+# This expects the BUILD_DIR to be a git repository, and441441+# will checkout the PATCHCHECK_START commit.442442+#443443+# The option BUILD_TYPE will be ignored.444444+#445445+# The MIN_CONFIG will be used for all builds of the patchcheck. The build type446446+# used for patchcheck is oldconfig.447447+#448448+# PATCHCHECK_START is required and is the first patch to449449+# test (the SHA1 of the commit). You may also specify anything450450+# that git checkout allows (branch name, tage, HEAD~3).451451+#452452+# PATCHCHECK_END is the last patch to check (default HEAD)453453+#454454+# PATCHCHECK_TYPE is required and is the type of test to run:455455+# build, boot, test.456456+#457457+# Note, the build test will look for warnings, if a warning occurred458458+# in a file that a commit touches, the build will fail.459459+#460460+# If BUILD_NOCLEAN is set, then make mrproper will not be run on461461+# any of the builds, just like all other TEST_TYPE tests. But462462+# what makes patchcheck different from the other tests, is if463463+# BUILD_NOCLEAN is not set, only the first and last patch run464464+# make mrproper. This helps speed up the test.465465+#466466+# Example:467467+# TEST_START468468+# TEST_TYPE = patchcheck469469+# CHECKOUT = mybranch470470+# PATCHCHECK_TYPE = boot471471+# PATCHCHECK_START = 747e94ae3d1b4c9bf5380e569f614eb9040b79e7472472+# PATCHCHECK_END = HEAD~2473473+#474474+#475475+#476476+# For TEST_TYPE = bisect477477+#478478+# You can specify a git bisect if the BUILD_DIR is a git repository.479479+# The MIN_CONFIG will be used for all builds of the bisect. The build type480480+# used for bisecting is oldconfig.481481+#482482+# The option BUILD_TYPE will be ignored.483483+#484484+# BISECT_TYPE is the type of test to perform:485485+# build - bad fails to build486486+# boot - bad builds but fails to boot487487+# test - bad boots but fails a test488488+#489489+# BISECT_GOOD is the commit (SHA1) to label as good (accepts all git good commit types)490490+# BISECT_BAD is the commit to label as bad (accepts all git bad commit types)491491+#492492+# The above three options are required for a bisect operation.493493+#494494+# BISECT_REPLAY = /path/to/replay/file (optional, default undefined)495495+#496496+# If an operation failed in the bisect that was not expected to497497+# fail. Then the test ends. The state of the BUILD_DIR will be498498+# left off at where the failure occurred. You can examine the499499+# reason for the failure, and perhaps even find a git commit500500+# that would work to continue with. You can run:501501+#502502+# git bisect log > /path/to/replay/file503503+#504504+# The adding:505505+#506506+# BISECT_REPLAY= /path/to/replay/file507507+#508508+# And running the test again. The test will perform the initial509509+# git bisect start, git bisect good, and git bisect bad, and510510+# then it will run git bisect replay on this file, before511511+# continuing with the bisect.512512+#513513+# BISECT_START = commit (optional, default undefined)514514+#515515+# As with BISECT_REPLAY, if the test failed on a commit that516516+# just happen to have a bad commit in the middle of the bisect,517517+# and you need to skip it. If BISECT_START is defined, it518518+# will checkout that commit after doing the initial git bisect start,519519+# git bisect good, git bisect bad, and running the git bisect replay520520+# if the BISECT_REPLAY is set.521521+#522522+# BISECT_REVERSE = 1 (optional, default 0)523523+#524524+# In those strange instances where it was broken forever525525+# and you are trying to find where it started to work!526526+# Set BISECT_GOOD to the commit that was last known to fail527527+# Set BISECT_BAD to the commit that is known to start working.528528+# With BISECT_REVERSE = 1, The test will consider failures as529529+# good, and success as bad.530530+#531531+# BISECT_CHECK = 1 (optional, default 0)532532+#533533+# Just to be sure the good is good and bad is bad, setting534534+# BISECT_CHECK to 1 will start the bisect by first checking535535+# out BISECT_BAD and makes sure it fails, then it will check536536+# out BISECT_GOOD and makes sure it succeeds before starting537537+# the bisect (it works for BISECT_REVERSE too).538538+#539539+# You can limit the test to just check BISECT_GOOD or540540+# BISECT_BAD with BISECT_CHECK = good or541541+# BISECT_CHECK = bad, respectively.542542+#543543+# Example:544544+# TEST_START545545+# TEST_TYPE = bisect546546+# BISECT_GOOD = v2.6.36547547+# BISECT_BAD = b5153163ed580e00c67bdfecb02b2e3843817b3e548548+# BISECT_TYPE = build549549+# MIN_CONFIG = /home/test/config-bisect550550+#551551+#552552+#553553+# For TEST_TYPE = config_bisect554554+#555555+# In those cases that you have two different configs. One of them556556+# work, the other does not, and you do not know what config causes557557+# the problem.558558+# The TEST_TYPE config_bisect will bisect the bad config looking for559559+# what config causes the failure.560560+#561561+# The way it works is this:562562+#563563+# First it finds a config to work with. Since a different version, or564564+# MIN_CONFIG may cause different dependecies, it must run through this565565+# preparation.566566+#567567+# Overwrites any config set in the bad config with a config set in568568+# either the MIN_CONFIG or ADD_CONFIG. Thus, make sure these configs569569+# are minimal and do not disable configs you want to test:570570+# (ie. # CONFIG_FOO is not set).571571+#572572+# An oldconfig is run on the bad config and any new config that573573+# appears will be added to the configs to test.574574+#575575+# Finally, it generates a config with the above result and runs it576576+# again through make oldconfig to produce a config that should be577577+# satisfied by kconfig.578578+#579579+# Then it starts the bisect.580580+#581581+# The configs to test are cut in half. If all the configs in this582582+# half depend on a config in the other half, then the other half583583+# is tested instead. If no configs are enabled by either half, then584584+# this means a circular dependency exists and the test fails.585585+#586586+# A config is created with the test half, and the bisect test is run.587587+#588588+# If the bisect succeeds, then all configs in the generated config589589+# are removed from the configs to test and added to the configs that590590+# will be enabled for all builds (they will be enabled, but not be part591591+# of the configs to examine).592592+#593593+# If the bisect fails, then all test configs that were not enabled by594594+# the config file are removed from the test. These configs will not595595+# be enabled in future tests. Since current config failed, we consider596596+# this to be a subset of the config that we started with.597597+#598598+# When we are down to one config, it is considered the bad config.599599+#600600+# Note, the config chosen may not be the true bad config. Due to601601+# dependencies and selections of the kbuild system, mulitple602602+# configs may be needed to cause a failure. If you disable the603603+# config that was found and restart the test, if the test fails604604+# again, it is recommended to rerun the config_bisect with a new605605+# bad config without the found config enabled.606606+#607607+# The option BUILD_TYPE will be ignored.608608+#609609+# CONFIG_BISECT_TYPE is the type of test to perform:610610+# build - bad fails to build611611+# boot - bad builds but fails to boot612612+# test - bad boots but fails a test613613+#614614+# CONFIG_BISECT is the config that failed to boot615615+#616616+# Example:617617+# TEST_START618618+# TEST_TYPE = config_bisect619619+# CONFIG_BISECT_TYPE = build620620+# CONFIG_BISECT = /home/test/�onfig-bad621621+# MIN_CONFIG = /home/test/config-min622622+#