From owner-freebsd-mobile@freebsd.org Fri Sep 25 16:58:27 2015 Return-Path: Delivered-To: freebsd-mobile@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 81D1BA08F02 for ; Fri, 25 Sep 2015 16:58:27 +0000 (UTC) (envelope-from Scoobi_doo@yahoo.com) Received: from nm6.bullet.mail.bf1.yahoo.com (nm6.bullet.mail.bf1.yahoo.com [98.139.212.165]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 45B11157D for ; Fri, 25 Sep 2015 16:58:26 +0000 (UTC) (envelope-from Scoobi_doo@yahoo.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1443200299; bh=Yk27UeUiYu0zDuScFq8qLSbQN0FZSDYjEcL5jB4fBsw=; h=Date:From:To:Subject:From:Subject; b=j5pM73dozzG9Wnw08bUCSi1tnIxE/a0G0AOXRZ3mnKn0+mbplfwSRKzZ0JiJqU143t5iIa3Y8JNXWTNd12QQbHpcxP36OzW6gCd50Y/RgNuh71w5ky2ghzK3xG2v7BrNGf1Wvy6UO/I8JuHzdS9EhTmlrnt60NivgcMEmFoBPTy2GN/U76dSqShmljXRIVyp7llB8MKxgvPCnOEN/wd62IHiUsytlL+Xnr+OcX1tTCRrzF8WJ1A0laOU7VMshiqOcjKgQbRRR8SxwQ9EDNTJrckhf2Bza4rvtM7EhKPEEG17vFy1wly6trZZdB3nhrOVe9d0TPMU4tML+xY1icQ3lQ== Received: from [66.196.81.173] by nm6.bullet.mail.bf1.yahoo.com with NNFMP; 25 Sep 2015 16:58:19 -0000 Received: from [68.142.230.78] by tm19.bullet.mail.bf1.yahoo.com with NNFMP; 25 Sep 2015 16:58:19 -0000 Received: from [127.0.0.1] by smtp235.mail.bf1.yahoo.com with NNFMP; 25 Sep 2015 16:58:19 -0000 X-Yahoo-Newman-Id: 783788.69430.bm@smtp235.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: GqDox48VM1mdqffDSiOUq_Mf0bCNJRU8oPFYWTNpkLUAdCJ IG1pFniOh8Edjw.YglfvGLimR8XJLt7KkpYMauS20hayRbA362NqlDDuiXlL 99YIhZGR3DjAMmWsNp1M8SUdx6qPMFfGqaA0wq9D6ZfChcmUgOIMpZ.8xbyh iNu70KSqAz8HBDi.sYNr5wtBNRaZaAPNXEip8yCd5PZybFousLoNPA9uSAWZ CPWNAi5cVGYTejjCsjp85LxQqCmvtak4OIspNMN5UGOKcfjAVgpanaF_KDT3 pI.p5avYa6A9Z3oC7qnU5GUHe70pRodRs_X0ZaWLyeoWb_I_X71W5pEOPiIn _2Hk49WyPvjqKMTQ0GM9Bl8R788AX9RkkjZr8p_J_L2p8EquKsy8mLGG0PHv 94JuxGmLUhd9XnfUmj1TTkzLU_ncS2fueTk2iq1_ZIH4yYw23C3ydTbj3GoK mM20xhT879xH7zDxVOgGnNOeOifHmMlliIkmX1v78DsLMoQ29CsFxGKfUFzM HNn4io..Iu0GavzzSHIxPNs2Rht3sbxT0 X-Yahoo-SMTP: 9sPoSQ2swBBlERuQ.0vs8XLc_MeClW0- Message-ID: <56057D2A.9090505@yahoo.com> Date: Fri, 25 Sep 2015 12:58:18 -0400 From: Anthony Jenkins Organization: VTilt Digital, LLC User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: "freebsd-mobile@freebsd.org" Subject: PATCH: cpufreq(4) support for modern AMD processors (git format) Content-Type: multipart/mixed; boundary="------------020102020707080202060604" X-BeenThere: freebsd-mobile@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mobile computing with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Sep 2015 16:58:27 -0000 This is a multi-part message in MIME format. --------------020102020707080202060604 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable sys/x86/cpufreq/hwpstate.c provides support for AMD CPUs, but only supports families up to 0x11. The latest AMD CPU family is 0x16. This patch adds support for newer AMD CPUs. (The patch to sys/x86/cpufreq/powernow.c is cosmetic/superfluous.) Sources: BIOS and Kernel Developer's Guide for AMD Family (10h|11h|12h|14h Models *|15h Models *|16h Models *) Processors I'm still looking into the occasional 'hwpstate0: set freq failed, err 6' error. hwpstate0 reports "error: loop is not enough" when attempting to set the P-state on my cores. CPU_FOREACH(i) { /* Bind to each cpu. */ thread_lock(curthread); sched_bind(curthread, i); thread_unlock(curthread); /* wait loop (100*100 usec is enough ?) */ for(j =3D 0; j < 100; j++){ /* get the result. not assure msr=3Did */ msr =3D rdmsr(MSR_AMD_10H_11H_STATUS); if(msr =3D=3D id){ break; } DELAY(100); } HWPSTATE_DEBUG(dev, "result P%d-state on cpu%d\n", (int)msr, PCPU_GET(cpuid)); if (msr !=3D id) { HWPSTATE_DEBUG(dev, "error: loop is not enough.\n= "); error =3D ENXIO; } } I haven't figured out a more deterministic way of knowing when to read the MSR after requesting the new P-state...still wading through the AMD CPU manuals. --=20 Anthony Jenkins Software Engineer Zenterio, Inc. USA --------------020102020707080202060604 Content-Type: text/x-patch; name="amd_hwpstate_support.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="amd_hwpstate_support.patch" diff --git a/sys/x86/cpufreq/hwpstate.c b/sys/x86/cpufreq/hwpstate.c index d4c70b7..326d967 100644 --- a/sys/x86/cpufreq/hwpstate.c +++ b/sys/x86/cpufreq/hwpstate.c @@ -408,25 +408,27 @@ hwpstate_get_info_from_msr(device_t dev) hwpstate_set =3D sc->hwpstate_settings; for (i =3D 0; i < sc->cfnum; i++) { msr =3D rdmsr(MSR_AMD_10H_11H_CONFIG + i); - if ((msr & ((uint64_t)1 << 63)) !=3D ((uint64_t)1 << 63)) { + if ((msr & ((uint64_t)1 << 63)) =3D=3D 0) { HWPSTATE_DEBUG(dev, "msr is not valid.\n"); return (ENXIO); } did =3D AMD_10H_11H_CUR_DID(msr); fid =3D AMD_10H_11H_CUR_FID(msr); + /* fid/did to frequency */ switch(family) { case 0x11: - /* fid/did to frequency */ - hwpstate_set[i].freq =3D 100 * (fid + 0x08) / (1 << did); + hwpstate_set[i].freq =3D (100 * (fid + 0x08)) >> did; break; case 0x10: - /* fid/did to frequency */ - hwpstate_set[i].freq =3D 100 * (fid + 0x10) / (1 << did); + case 0x12: + case 0x14: + case 0x15: + case 0x16: + hwpstate_set[i].freq =3D (100 * (fid + 0x10)) >> did; break; default: - HWPSTATE_DEBUG(dev, "get_info_from_msr: AMD family %d CPU's are not i= mplemented yet. sorry.\n", family); + HWPSTATE_DEBUG(dev, "get_info_from_msr: AMD family 0x%02x CPU's are n= ot implemented yet. sorry.\n", family); return (ENXIO); - break; } hwpstate_set[i].pstate_id =3D i; /* There was volts calculation, but deleted it. */ diff --git a/sys/x86/cpufreq/powernow.c b/sys/x86/cpufreq/powernow.c index cc62e87..355bde8 100644 --- a/sys/x86/cpufreq/powernow.c +++ b/sys/x86/cpufreq/powernow.c @@ -866,17 +866,22 @@ static void pn_identify(driver_t *driver, device_t parent) { =20 - if ((amd_pminfo & AMDPM_FID) =3D=3D 0 || (amd_pminfo & AMDPM_VID) =3D=3D= 0) + if ((amd_pminfo & AMDPM_FID) =3D=3D 0 || (amd_pminfo & AMDPM_VID) =3D=3D= 0) { + printf("powernow: pn_identify: amd_pminfo=3D0x%04x .\n", amd_pminfo); return; + } switch (cpu_id & 0xf00) { case 0x600: case 0xf00: break; default: + printf("powernow: pn_identify: cpu_id=3D0x%04x.\n", cpu_id); return; } - if (device_find_child(parent, "powernow", -1) !=3D NULL) + if (device_find_child(parent, "powernow", -1) !=3D NULL) { + printf("powernow: pn_identify: No \"powernow\"device found.\n"); return; + } if (BUS_ADD_CHILD(parent, 10, "powernow", -1) =3D=3D NULL) device_printf(parent, "powernow: add child failed\n"); } @@ -895,8 +900,10 @@ pn_probe(device_t dev) status =3D rdmsr(MSR_AMDK7_FIDVID_STATUS); =20 pc =3D cpu_get_pcpu(dev); - if (pc =3D=3D NULL) + if (pc =3D=3D NULL) { + printf("powernow: cpu_get_pcpu() returned NULL.\n"); return (ENODEV); + } =20 cpu_est_clockrate(pc->pc_cpuid, &rate); =20 @@ -936,6 +943,7 @@ pn_probe(device_t dev) device_set_desc(dev, "Cool`n'Quiet K8"); break; default: + printf("powernow: cpuid 0x%04x & 0xf00 not matched.\n", cpu_id); return (ENODEV); } =20 --------------020102020707080202060604--