realtime.patch 767 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664
  1. diff -Nur linux-4.1.6.orig/arch/alpha/mm/fault.c linux-4.1.6/arch/alpha/mm/fault.c
  2. --- linux-4.1.6.orig/arch/alpha/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  3. +++ linux-4.1.6/arch/alpha/mm/fault.c 2015-09-08 23:49:03.498378314 +0200
  4. @@ -23,8 +23,7 @@
  5. #include <linux/smp.h>
  6. #include <linux/interrupt.h>
  7. #include <linux/module.h>
  8. -
  9. -#include <asm/uaccess.h>
  10. +#include <linux/uaccess.h>
  11. extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
  12. @@ -107,7 +106,7 @@
  13. /* If we're in an interrupt context, or have no user context,
  14. we must not take the fault. */
  15. - if (!mm || in_atomic())
  16. + if (!mm || faulthandler_disabled())
  17. goto no_context;
  18. #ifdef CONFIG_ALPHA_LARGE_VMALLOC
  19. diff -Nur linux-4.1.6.orig/arch/arc/include/asm/futex.h linux-4.1.6/arch/arc/include/asm/futex.h
  20. --- linux-4.1.6.orig/arch/arc/include/asm/futex.h 2015-08-17 05:52:51.000000000 +0200
  21. +++ linux-4.1.6/arch/arc/include/asm/futex.h 2015-09-08 23:49:03.498378314 +0200
  22. @@ -53,7 +53,7 @@
  23. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
  24. return -EFAULT;
  25. - pagefault_disable(); /* implies preempt_disable() */
  26. + pagefault_disable();
  27. switch (op) {
  28. case FUTEX_OP_SET:
  29. @@ -75,7 +75,7 @@
  30. ret = -ENOSYS;
  31. }
  32. - pagefault_enable(); /* subsumes preempt_enable() */
  33. + pagefault_enable();
  34. if (!ret) {
  35. switch (cmp) {
  36. @@ -104,7 +104,7 @@
  37. return ret;
  38. }
  39. -/* Compare-xchg with preemption disabled.
  40. +/* Compare-xchg with pagefaults disabled.
  41. * Notes:
  42. * -Best-Effort: Exchg happens only if compare succeeds.
  43. * If compare fails, returns; leaving retry/looping to upper layers
  44. @@ -121,7 +121,7 @@
  45. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
  46. return -EFAULT;
  47. - pagefault_disable(); /* implies preempt_disable() */
  48. + pagefault_disable();
  49. /* TBD : can use llock/scond */
  50. __asm__ __volatile__(
  51. @@ -142,7 +142,7 @@
  52. : "r"(oldval), "r"(newval), "r"(uaddr), "ir"(-EFAULT)
  53. : "cc", "memory");
  54. - pagefault_enable(); /* subsumes preempt_enable() */
  55. + pagefault_enable();
  56. *uval = val;
  57. return val;
  58. diff -Nur linux-4.1.6.orig/arch/arc/mm/fault.c linux-4.1.6/arch/arc/mm/fault.c
  59. --- linux-4.1.6.orig/arch/arc/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  60. +++ linux-4.1.6/arch/arc/mm/fault.c 2015-09-08 23:49:03.498378314 +0200
  61. @@ -86,7 +86,7 @@
  62. * If we're in an interrupt or have no user
  63. * context, we must not take the fault..
  64. */
  65. - if (in_atomic() || !mm)
  66. + if (faulthandler_disabled() || !mm)
  67. goto no_context;
  68. if (user_mode(regs))
  69. diff -Nur linux-4.1.6.orig/arch/arm/include/asm/cmpxchg.h linux-4.1.6/arch/arm/include/asm/cmpxchg.h
  70. --- linux-4.1.6.orig/arch/arm/include/asm/cmpxchg.h 2015-08-17 05:52:51.000000000 +0200
  71. +++ linux-4.1.6/arch/arm/include/asm/cmpxchg.h 2015-09-08 23:49:03.498378314 +0200
  72. @@ -129,6 +129,8 @@
  73. #else /* min ARCH >= ARMv6 */
  74. +#define __HAVE_ARCH_CMPXCHG 1
  75. +
  76. extern void __bad_cmpxchg(volatile void *ptr, int size);
  77. /*
  78. diff -Nur linux-4.1.6.orig/arch/arm/include/asm/futex.h linux-4.1.6/arch/arm/include/asm/futex.h
  79. --- linux-4.1.6.orig/arch/arm/include/asm/futex.h 2015-08-17 05:52:51.000000000 +0200
  80. +++ linux-4.1.6/arch/arm/include/asm/futex.h 2015-09-08 23:49:03.498378314 +0200
  81. @@ -93,6 +93,7 @@
  82. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  83. return -EFAULT;
  84. + preempt_disable();
  85. __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
  86. "1: " TUSER(ldr) " %1, [%4]\n"
  87. " teq %1, %2\n"
  88. @@ -104,6 +105,8 @@
  89. : "cc", "memory");
  90. *uval = val;
  91. + preempt_enable();
  92. +
  93. return ret;
  94. }
  95. @@ -124,7 +127,10 @@
  96. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  97. return -EFAULT;
  98. - pagefault_disable(); /* implies preempt_disable() */
  99. +#ifndef CONFIG_SMP
  100. + preempt_disable();
  101. +#endif
  102. + pagefault_disable();
  103. switch (op) {
  104. case FUTEX_OP_SET:
  105. @@ -146,7 +152,10 @@
  106. ret = -ENOSYS;
  107. }
  108. - pagefault_enable(); /* subsumes preempt_enable() */
  109. + pagefault_enable();
  110. +#ifndef CONFIG_SMP
  111. + preempt_enable();
  112. +#endif
  113. if (!ret) {
  114. switch (cmp) {
  115. diff -Nur linux-4.1.6.orig/arch/arm/include/asm/switch_to.h linux-4.1.6/arch/arm/include/asm/switch_to.h
  116. --- linux-4.1.6.orig/arch/arm/include/asm/switch_to.h 2015-08-17 05:52:51.000000000 +0200
  117. +++ linux-4.1.6/arch/arm/include/asm/switch_to.h 2015-09-08 23:49:03.498378314 +0200
  118. @@ -3,6 +3,13 @@
  119. #include <linux/thread_info.h>
  120. +#if defined CONFIG_PREEMPT_RT_FULL && defined CONFIG_HIGHMEM
  121. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p);
  122. +#else
  123. +static inline void
  124. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  125. +#endif
  126. +
  127. /*
  128. * For v7 SMP cores running a preemptible kernel we may be pre-empted
  129. * during a TLB maintenance operation, so execute an inner-shareable dsb
  130. @@ -22,6 +29,7 @@
  131. #define switch_to(prev,next,last) \
  132. do { \
  133. + switch_kmaps(prev, next); \
  134. last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \
  135. } while (0)
  136. diff -Nur linux-4.1.6.orig/arch/arm/include/asm/thread_info.h linux-4.1.6/arch/arm/include/asm/thread_info.h
  137. --- linux-4.1.6.orig/arch/arm/include/asm/thread_info.h 2015-08-17 05:52:51.000000000 +0200
  138. +++ linux-4.1.6/arch/arm/include/asm/thread_info.h 2015-09-08 23:49:03.498378314 +0200
  139. @@ -50,6 +50,7 @@
  140. struct thread_info {
  141. unsigned long flags; /* low level flags */
  142. int preempt_count; /* 0 => preemptable, <0 => bug */
  143. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  144. mm_segment_t addr_limit; /* address limit */
  145. struct task_struct *task; /* main task structure */
  146. __u32 cpu; /* cpu */
  147. @@ -147,6 +148,7 @@
  148. #define TIF_SIGPENDING 0
  149. #define TIF_NEED_RESCHED 1
  150. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  151. +#define TIF_NEED_RESCHED_LAZY 3
  152. #define TIF_UPROBE 7
  153. #define TIF_SYSCALL_TRACE 8
  154. #define TIF_SYSCALL_AUDIT 9
  155. @@ -160,6 +162,7 @@
  156. #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  157. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  158. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  159. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  160. #define _TIF_UPROBE (1 << TIF_UPROBE)
  161. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  162. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  163. diff -Nur linux-4.1.6.orig/arch/arm/Kconfig linux-4.1.6/arch/arm/Kconfig
  164. --- linux-4.1.6.orig/arch/arm/Kconfig 2015-08-17 05:52:51.000000000 +0200
  165. +++ linux-4.1.6/arch/arm/Kconfig 2015-09-08 23:49:03.498378314 +0200
  166. @@ -31,7 +31,7 @@
  167. select HARDIRQS_SW_RESEND
  168. select HAVE_ARCH_AUDITSYSCALL if (AEABI && !OABI_COMPAT)
  169. select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
  170. - select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
  171. + select HAVE_ARCH_JUMP_LABEL if (!XIP_KERNEL && !PREEMPT_RT_BASE)
  172. select HAVE_ARCH_KGDB
  173. select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
  174. select HAVE_ARCH_TRACEHOOK
  175. @@ -66,6 +66,7 @@
  176. select HAVE_PERF_EVENTS
  177. select HAVE_PERF_REGS
  178. select HAVE_PERF_USER_STACK_DUMP
  179. + select HAVE_PREEMPT_LAZY
  180. select HAVE_RCU_TABLE_FREE if (SMP && ARM_LPAE)
  181. select HAVE_REGS_AND_STACK_ACCESS_API
  182. select HAVE_SYSCALL_TRACEPOINTS
  183. diff -Nur linux-4.1.6.orig/arch/arm/kernel/asm-offsets.c linux-4.1.6/arch/arm/kernel/asm-offsets.c
  184. --- linux-4.1.6.orig/arch/arm/kernel/asm-offsets.c 2015-08-17 05:52:51.000000000 +0200
  185. +++ linux-4.1.6/arch/arm/kernel/asm-offsets.c 2015-09-08 23:49:03.498378314 +0200
  186. @@ -65,6 +65,7 @@
  187. BLANK();
  188. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  189. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  190. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  191. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  192. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  193. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  194. diff -Nur linux-4.1.6.orig/arch/arm/kernel/entry-armv.S linux-4.1.6/arch/arm/kernel/entry-armv.S
  195. --- linux-4.1.6.orig/arch/arm/kernel/entry-armv.S 2015-08-17 05:52:51.000000000 +0200
  196. +++ linux-4.1.6/arch/arm/kernel/entry-armv.S 2015-09-08 23:49:03.498378314 +0200
  197. @@ -208,11 +208,18 @@
  198. #ifdef CONFIG_PREEMPT
  199. get_thread_info tsk
  200. ldr r8, [tsk, #TI_PREEMPT] @ get preempt count
  201. - ldr r0, [tsk, #TI_FLAGS] @ get flags
  202. teq r8, #0 @ if preempt count != 0
  203. + bne 1f @ return from exeption
  204. + ldr r0, [tsk, #TI_FLAGS] @ get flags
  205. + tst r0, #_TIF_NEED_RESCHED @ if NEED_RESCHED is set
  206. + blne svc_preempt @ preempt!
  207. +
  208. + ldr r8, [tsk, #TI_PREEMPT_LAZY] @ get preempt lazy count
  209. + teq r8, #0 @ if preempt lazy count != 0
  210. movne r0, #0 @ force flags to 0
  211. - tst r0, #_TIF_NEED_RESCHED
  212. + tst r0, #_TIF_NEED_RESCHED_LAZY
  213. blne svc_preempt
  214. +1:
  215. #endif
  216. svc_exit r5, irq = 1 @ return from exception
  217. @@ -227,6 +234,8 @@
  218. 1: bl preempt_schedule_irq @ irq en/disable is done inside
  219. ldr r0, [tsk, #TI_FLAGS] @ get new tasks TI_FLAGS
  220. tst r0, #_TIF_NEED_RESCHED
  221. + bne 1b
  222. + tst r0, #_TIF_NEED_RESCHED_LAZY
  223. reteq r8 @ go again
  224. b 1b
  225. #endif
  226. diff -Nur linux-4.1.6.orig/arch/arm/kernel/process.c linux-4.1.6/arch/arm/kernel/process.c
  227. --- linux-4.1.6.orig/arch/arm/kernel/process.c 2015-08-17 05:52:51.000000000 +0200
  228. +++ linux-4.1.6/arch/arm/kernel/process.c 2015-09-08 23:49:03.498378314 +0200
  229. @@ -290,6 +290,30 @@
  230. }
  231. #ifdef CONFIG_MMU
  232. +/*
  233. + * CONFIG_SPLIT_PTLOCK_CPUS results in a page->ptl lock. If the lock is not
  234. + * initialized by pgtable_page_ctor() then a coredump of the vector page will
  235. + * fail.
  236. + */
  237. +static int __init vectors_user_mapping_init_page(void)
  238. +{
  239. + struct page *page;
  240. + unsigned long addr = 0xffff0000;
  241. + pgd_t *pgd;
  242. + pud_t *pud;
  243. + pmd_t *pmd;
  244. +
  245. + pgd = pgd_offset_k(addr);
  246. + pud = pud_offset(pgd, addr);
  247. + pmd = pmd_offset(pud, addr);
  248. + page = pmd_page(*(pmd));
  249. +
  250. + pgtable_page_ctor(page);
  251. +
  252. + return 0;
  253. +}
  254. +late_initcall(vectors_user_mapping_init_page);
  255. +
  256. #ifdef CONFIG_KUSER_HELPERS
  257. /*
  258. * The vectors page is always readable from user space for the
  259. diff -Nur linux-4.1.6.orig/arch/arm/kernel/signal.c linux-4.1.6/arch/arm/kernel/signal.c
  260. --- linux-4.1.6.orig/arch/arm/kernel/signal.c 2015-08-17 05:52:51.000000000 +0200
  261. +++ linux-4.1.6/arch/arm/kernel/signal.c 2015-09-08 23:49:03.498378314 +0200
  262. @@ -563,7 +563,8 @@
  263. do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
  264. {
  265. do {
  266. - if (likely(thread_flags & _TIF_NEED_RESCHED)) {
  267. + if (likely(thread_flags & (_TIF_NEED_RESCHED |
  268. + _TIF_NEED_RESCHED_LAZY))) {
  269. schedule();
  270. } else {
  271. if (unlikely(!user_mode(regs)))
  272. diff -Nur linux-4.1.6.orig/arch/arm/kernel/unwind.c linux-4.1.6/arch/arm/kernel/unwind.c
  273. --- linux-4.1.6.orig/arch/arm/kernel/unwind.c 2015-08-17 05:52:51.000000000 +0200
  274. +++ linux-4.1.6/arch/arm/kernel/unwind.c 2015-09-08 23:49:03.498378314 +0200
  275. @@ -93,7 +93,7 @@
  276. static const struct unwind_idx *__origin_unwind_idx;
  277. extern const struct unwind_idx __stop_unwind_idx[];
  278. -static DEFINE_SPINLOCK(unwind_lock);
  279. +static DEFINE_RAW_SPINLOCK(unwind_lock);
  280. static LIST_HEAD(unwind_tables);
  281. /* Convert a prel31 symbol to an absolute address */
  282. @@ -201,7 +201,7 @@
  283. /* module unwind tables */
  284. struct unwind_table *table;
  285. - spin_lock_irqsave(&unwind_lock, flags);
  286. + raw_spin_lock_irqsave(&unwind_lock, flags);
  287. list_for_each_entry(table, &unwind_tables, list) {
  288. if (addr >= table->begin_addr &&
  289. addr < table->end_addr) {
  290. @@ -213,7 +213,7 @@
  291. break;
  292. }
  293. }
  294. - spin_unlock_irqrestore(&unwind_lock, flags);
  295. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  296. }
  297. pr_debug("%s: idx = %p\n", __func__, idx);
  298. @@ -529,9 +529,9 @@
  299. tab->begin_addr = text_addr;
  300. tab->end_addr = text_addr + text_size;
  301. - spin_lock_irqsave(&unwind_lock, flags);
  302. + raw_spin_lock_irqsave(&unwind_lock, flags);
  303. list_add_tail(&tab->list, &unwind_tables);
  304. - spin_unlock_irqrestore(&unwind_lock, flags);
  305. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  306. return tab;
  307. }
  308. @@ -543,9 +543,9 @@
  309. if (!tab)
  310. return;
  311. - spin_lock_irqsave(&unwind_lock, flags);
  312. + raw_spin_lock_irqsave(&unwind_lock, flags);
  313. list_del(&tab->list);
  314. - spin_unlock_irqrestore(&unwind_lock, flags);
  315. + raw_spin_unlock_irqrestore(&unwind_lock, flags);
  316. kfree(tab);
  317. }
  318. diff -Nur linux-4.1.6.orig/arch/arm/kvm/arm.c linux-4.1.6/arch/arm/kvm/arm.c
  319. --- linux-4.1.6.orig/arch/arm/kvm/arm.c 2015-08-17 05:52:51.000000000 +0200
  320. +++ linux-4.1.6/arch/arm/kvm/arm.c 2015-09-08 23:49:03.498378314 +0200
  321. @@ -474,9 +474,9 @@
  322. static void vcpu_pause(struct kvm_vcpu *vcpu)
  323. {
  324. - wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu);
  325. + struct swait_head *wq = kvm_arch_vcpu_wq(vcpu);
  326. - wait_event_interruptible(*wq, !vcpu->arch.pause);
  327. + swait_event_interruptible(*wq, !vcpu->arch.pause);
  328. }
  329. static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu)
  330. diff -Nur linux-4.1.6.orig/arch/arm/kvm/psci.c linux-4.1.6/arch/arm/kvm/psci.c
  331. --- linux-4.1.6.orig/arch/arm/kvm/psci.c 2015-08-17 05:52:51.000000000 +0200
  332. +++ linux-4.1.6/arch/arm/kvm/psci.c 2015-09-08 23:49:03.498378314 +0200
  333. @@ -68,7 +68,7 @@
  334. {
  335. struct kvm *kvm = source_vcpu->kvm;
  336. struct kvm_vcpu *vcpu = NULL;
  337. - wait_queue_head_t *wq;
  338. + struct swait_head *wq;
  339. unsigned long cpu_id;
  340. unsigned long context_id;
  341. phys_addr_t target_pc;
  342. @@ -117,7 +117,7 @@
  343. smp_mb(); /* Make sure the above is visible */
  344. wq = kvm_arch_vcpu_wq(vcpu);
  345. - wake_up_interruptible(wq);
  346. + swait_wake_interruptible(wq);
  347. return PSCI_RET_SUCCESS;
  348. }
  349. diff -Nur linux-4.1.6.orig/arch/arm/mach-exynos/platsmp.c linux-4.1.6/arch/arm/mach-exynos/platsmp.c
  350. --- linux-4.1.6.orig/arch/arm/mach-exynos/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  351. +++ linux-4.1.6/arch/arm/mach-exynos/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  352. @@ -231,7 +231,7 @@
  353. return (void __iomem *)(S5P_VA_SCU);
  354. }
  355. -static DEFINE_SPINLOCK(boot_lock);
  356. +static DEFINE_RAW_SPINLOCK(boot_lock);
  357. static void exynos_secondary_init(unsigned int cpu)
  358. {
  359. @@ -244,8 +244,8 @@
  360. /*
  361. * Synchronise with the boot thread.
  362. */
  363. - spin_lock(&boot_lock);
  364. - spin_unlock(&boot_lock);
  365. + raw_spin_lock(&boot_lock);
  366. + raw_spin_unlock(&boot_lock);
  367. }
  368. static int exynos_boot_secondary(unsigned int cpu, struct task_struct *idle)
  369. @@ -259,7 +259,7 @@
  370. * Set synchronisation state between this boot processor
  371. * and the secondary one
  372. */
  373. - spin_lock(&boot_lock);
  374. + raw_spin_lock(&boot_lock);
  375. /*
  376. * The secondary processor is waiting to be released from
  377. @@ -286,7 +286,7 @@
  378. if (timeout == 0) {
  379. printk(KERN_ERR "cpu1 power enable failed");
  380. - spin_unlock(&boot_lock);
  381. + raw_spin_unlock(&boot_lock);
  382. return -ETIMEDOUT;
  383. }
  384. }
  385. @@ -342,7 +342,7 @@
  386. * calibrations, then wait for it to finish
  387. */
  388. fail:
  389. - spin_unlock(&boot_lock);
  390. + raw_spin_unlock(&boot_lock);
  391. return pen_release != -1 ? ret : 0;
  392. }
  393. diff -Nur linux-4.1.6.orig/arch/arm/mach-hisi/platmcpm.c linux-4.1.6/arch/arm/mach-hisi/platmcpm.c
  394. --- linux-4.1.6.orig/arch/arm/mach-hisi/platmcpm.c 2015-08-17 05:52:51.000000000 +0200
  395. +++ linux-4.1.6/arch/arm/mach-hisi/platmcpm.c 2015-09-08 23:49:03.498378314 +0200
  396. @@ -57,7 +57,7 @@
  397. static void __iomem *sysctrl, *fabric;
  398. static int hip04_cpu_table[HIP04_MAX_CLUSTERS][HIP04_MAX_CPUS_PER_CLUSTER];
  399. -static DEFINE_SPINLOCK(boot_lock);
  400. +static DEFINE_RAW_SPINLOCK(boot_lock);
  401. static u32 fabric_phys_addr;
  402. /*
  403. * [0]: bootwrapper physical address
  404. @@ -104,7 +104,7 @@
  405. if (cluster >= HIP04_MAX_CLUSTERS || cpu >= HIP04_MAX_CPUS_PER_CLUSTER)
  406. return -EINVAL;
  407. - spin_lock_irq(&boot_lock);
  408. + raw_spin_lock_irq(&boot_lock);
  409. if (hip04_cpu_table[cluster][cpu])
  410. goto out;
  411. @@ -133,7 +133,7 @@
  412. udelay(20);
  413. out:
  414. hip04_cpu_table[cluster][cpu]++;
  415. - spin_unlock_irq(&boot_lock);
  416. + raw_spin_unlock_irq(&boot_lock);
  417. return 0;
  418. }
  419. @@ -149,7 +149,7 @@
  420. __mcpm_cpu_going_down(cpu, cluster);
  421. - spin_lock(&boot_lock);
  422. + raw_spin_lock(&boot_lock);
  423. BUG_ON(__mcpm_cluster_state(cluster) != CLUSTER_UP);
  424. hip04_cpu_table[cluster][cpu]--;
  425. if (hip04_cpu_table[cluster][cpu] == 1) {
  426. @@ -162,7 +162,7 @@
  427. last_man = hip04_cluster_is_down(cluster);
  428. if (last_man && __mcpm_outbound_enter_critical(cpu, cluster)) {
  429. - spin_unlock(&boot_lock);
  430. + raw_spin_unlock(&boot_lock);
  431. /* Since it's Cortex A15, disable L2 prefetching. */
  432. asm volatile(
  433. "mcr p15, 1, %0, c15, c0, 3 \n\t"
  434. @@ -173,7 +173,7 @@
  435. hip04_set_snoop_filter(cluster, 0);
  436. __mcpm_outbound_leave_critical(cluster, CLUSTER_DOWN);
  437. } else {
  438. - spin_unlock(&boot_lock);
  439. + raw_spin_unlock(&boot_lock);
  440. v7_exit_coherency_flush(louis);
  441. }
  442. @@ -192,7 +192,7 @@
  443. cpu >= HIP04_MAX_CPUS_PER_CLUSTER);
  444. count = TIMEOUT_MSEC / POLL_MSEC;
  445. - spin_lock_irq(&boot_lock);
  446. + raw_spin_lock_irq(&boot_lock);
  447. for (tries = 0; tries < count; tries++) {
  448. if (hip04_cpu_table[cluster][cpu]) {
  449. ret = -EBUSY;
  450. @@ -202,10 +202,10 @@
  451. data = readl_relaxed(sysctrl + SC_CPU_RESET_STATUS(cluster));
  452. if (data & CORE_WFI_STATUS(cpu))
  453. break;
  454. - spin_unlock_irq(&boot_lock);
  455. + raw_spin_unlock_irq(&boot_lock);
  456. /* Wait for clean L2 when the whole cluster is down. */
  457. msleep(POLL_MSEC);
  458. - spin_lock_irq(&boot_lock);
  459. + raw_spin_lock_irq(&boot_lock);
  460. }
  461. if (tries >= count)
  462. goto err;
  463. @@ -220,10 +220,10 @@
  464. }
  465. if (tries >= count)
  466. goto err;
  467. - spin_unlock_irq(&boot_lock);
  468. + raw_spin_unlock_irq(&boot_lock);
  469. return 0;
  470. err:
  471. - spin_unlock_irq(&boot_lock);
  472. + raw_spin_unlock_irq(&boot_lock);
  473. return ret;
  474. }
  475. @@ -235,10 +235,10 @@
  476. cpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
  477. cluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
  478. - spin_lock(&boot_lock);
  479. + raw_spin_lock(&boot_lock);
  480. if (!hip04_cpu_table[cluster][cpu])
  481. hip04_cpu_table[cluster][cpu] = 1;
  482. - spin_unlock(&boot_lock);
  483. + raw_spin_unlock(&boot_lock);
  484. }
  485. static void __naked hip04_mcpm_power_up_setup(unsigned int affinity_level)
  486. diff -Nur linux-4.1.6.orig/arch/arm/mach-omap2/omap-smp.c linux-4.1.6/arch/arm/mach-omap2/omap-smp.c
  487. --- linux-4.1.6.orig/arch/arm/mach-omap2/omap-smp.c 2015-08-17 05:52:51.000000000 +0200
  488. +++ linux-4.1.6/arch/arm/mach-omap2/omap-smp.c 2015-09-08 23:49:03.498378314 +0200
  489. @@ -43,7 +43,7 @@
  490. /* SCU base address */
  491. static void __iomem *scu_base;
  492. -static DEFINE_SPINLOCK(boot_lock);
  493. +static DEFINE_RAW_SPINLOCK(boot_lock);
  494. void __iomem *omap4_get_scu_base(void)
  495. {
  496. @@ -74,8 +74,8 @@
  497. /*
  498. * Synchronise with the boot thread.
  499. */
  500. - spin_lock(&boot_lock);
  501. - spin_unlock(&boot_lock);
  502. + raw_spin_lock(&boot_lock);
  503. + raw_spin_unlock(&boot_lock);
  504. }
  505. static int omap4_boot_secondary(unsigned int cpu, struct task_struct *idle)
  506. @@ -89,7 +89,7 @@
  507. * Set synchronisation state between this boot processor
  508. * and the secondary one
  509. */
  510. - spin_lock(&boot_lock);
  511. + raw_spin_lock(&boot_lock);
  512. /*
  513. * Update the AuxCoreBoot0 with boot state for secondary core.
  514. @@ -166,7 +166,7 @@
  515. * Now the secondary core is starting up let it run its
  516. * calibrations, then wait for it to finish
  517. */
  518. - spin_unlock(&boot_lock);
  519. + raw_spin_unlock(&boot_lock);
  520. return 0;
  521. }
  522. diff -Nur linux-4.1.6.orig/arch/arm/mach-prima2/platsmp.c linux-4.1.6/arch/arm/mach-prima2/platsmp.c
  523. --- linux-4.1.6.orig/arch/arm/mach-prima2/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  524. +++ linux-4.1.6/arch/arm/mach-prima2/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  525. @@ -22,7 +22,7 @@
  526. static void __iomem *clk_base;
  527. -static DEFINE_SPINLOCK(boot_lock);
  528. +static DEFINE_RAW_SPINLOCK(boot_lock);
  529. static void sirfsoc_secondary_init(unsigned int cpu)
  530. {
  531. @@ -36,8 +36,8 @@
  532. /*
  533. * Synchronise with the boot thread.
  534. */
  535. - spin_lock(&boot_lock);
  536. - spin_unlock(&boot_lock);
  537. + raw_spin_lock(&boot_lock);
  538. + raw_spin_unlock(&boot_lock);
  539. }
  540. static const struct of_device_id clk_ids[] = {
  541. @@ -75,7 +75,7 @@
  542. /* make sure write buffer is drained */
  543. mb();
  544. - spin_lock(&boot_lock);
  545. + raw_spin_lock(&boot_lock);
  546. /*
  547. * The secondary processor is waiting to be released from
  548. @@ -107,7 +107,7 @@
  549. * now the secondary core is starting up let it run its
  550. * calibrations, then wait for it to finish
  551. */
  552. - spin_unlock(&boot_lock);
  553. + raw_spin_unlock(&boot_lock);
  554. return pen_release != -1 ? -ENOSYS : 0;
  555. }
  556. diff -Nur linux-4.1.6.orig/arch/arm/mach-qcom/platsmp.c linux-4.1.6/arch/arm/mach-qcom/platsmp.c
  557. --- linux-4.1.6.orig/arch/arm/mach-qcom/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  558. +++ linux-4.1.6/arch/arm/mach-qcom/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  559. @@ -46,7 +46,7 @@
  560. extern void secondary_startup_arm(void);
  561. -static DEFINE_SPINLOCK(boot_lock);
  562. +static DEFINE_RAW_SPINLOCK(boot_lock);
  563. #ifdef CONFIG_HOTPLUG_CPU
  564. static void __ref qcom_cpu_die(unsigned int cpu)
  565. @@ -60,8 +60,8 @@
  566. /*
  567. * Synchronise with the boot thread.
  568. */
  569. - spin_lock(&boot_lock);
  570. - spin_unlock(&boot_lock);
  571. + raw_spin_lock(&boot_lock);
  572. + raw_spin_unlock(&boot_lock);
  573. }
  574. static int scss_release_secondary(unsigned int cpu)
  575. @@ -284,7 +284,7 @@
  576. * set synchronisation state between this boot processor
  577. * and the secondary one
  578. */
  579. - spin_lock(&boot_lock);
  580. + raw_spin_lock(&boot_lock);
  581. /*
  582. * Send the secondary CPU a soft interrupt, thereby causing
  583. @@ -297,7 +297,7 @@
  584. * now the secondary core is starting up let it run its
  585. * calibrations, then wait for it to finish
  586. */
  587. - spin_unlock(&boot_lock);
  588. + raw_spin_unlock(&boot_lock);
  589. return ret;
  590. }
  591. diff -Nur linux-4.1.6.orig/arch/arm/mach-spear/platsmp.c linux-4.1.6/arch/arm/mach-spear/platsmp.c
  592. --- linux-4.1.6.orig/arch/arm/mach-spear/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  593. +++ linux-4.1.6/arch/arm/mach-spear/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  594. @@ -32,7 +32,7 @@
  595. sync_cache_w(&pen_release);
  596. }
  597. -static DEFINE_SPINLOCK(boot_lock);
  598. +static DEFINE_RAW_SPINLOCK(boot_lock);
  599. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  600. @@ -47,8 +47,8 @@
  601. /*
  602. * Synchronise with the boot thread.
  603. */
  604. - spin_lock(&boot_lock);
  605. - spin_unlock(&boot_lock);
  606. + raw_spin_lock(&boot_lock);
  607. + raw_spin_unlock(&boot_lock);
  608. }
  609. static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  610. @@ -59,7 +59,7 @@
  611. * set synchronisation state between this boot processor
  612. * and the secondary one
  613. */
  614. - spin_lock(&boot_lock);
  615. + raw_spin_lock(&boot_lock);
  616. /*
  617. * The secondary processor is waiting to be released from
  618. @@ -84,7 +84,7 @@
  619. * now the secondary core is starting up let it run its
  620. * calibrations, then wait for it to finish
  621. */
  622. - spin_unlock(&boot_lock);
  623. + raw_spin_unlock(&boot_lock);
  624. return pen_release != -1 ? -ENOSYS : 0;
  625. }
  626. diff -Nur linux-4.1.6.orig/arch/arm/mach-sti/platsmp.c linux-4.1.6/arch/arm/mach-sti/platsmp.c
  627. --- linux-4.1.6.orig/arch/arm/mach-sti/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  628. +++ linux-4.1.6/arch/arm/mach-sti/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  629. @@ -34,7 +34,7 @@
  630. sync_cache_w(&pen_release);
  631. }
  632. -static DEFINE_SPINLOCK(boot_lock);
  633. +static DEFINE_RAW_SPINLOCK(boot_lock);
  634. static void sti_secondary_init(unsigned int cpu)
  635. {
  636. @@ -49,8 +49,8 @@
  637. /*
  638. * Synchronise with the boot thread.
  639. */
  640. - spin_lock(&boot_lock);
  641. - spin_unlock(&boot_lock);
  642. + raw_spin_lock(&boot_lock);
  643. + raw_spin_unlock(&boot_lock);
  644. }
  645. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  646. @@ -61,7 +61,7 @@
  647. * set synchronisation state between this boot processor
  648. * and the secondary one
  649. */
  650. - spin_lock(&boot_lock);
  651. + raw_spin_lock(&boot_lock);
  652. /*
  653. * The secondary processor is waiting to be released from
  654. @@ -92,7 +92,7 @@
  655. * now the secondary core is starting up let it run its
  656. * calibrations, then wait for it to finish
  657. */
  658. - spin_unlock(&boot_lock);
  659. + raw_spin_unlock(&boot_lock);
  660. return pen_release != -1 ? -ENOSYS : 0;
  661. }
  662. diff -Nur linux-4.1.6.orig/arch/arm/mach-ux500/platsmp.c linux-4.1.6/arch/arm/mach-ux500/platsmp.c
  663. --- linux-4.1.6.orig/arch/arm/mach-ux500/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  664. +++ linux-4.1.6/arch/arm/mach-ux500/platsmp.c 2015-09-08 23:49:03.498378314 +0200
  665. @@ -51,7 +51,7 @@
  666. return NULL;
  667. }
  668. -static DEFINE_SPINLOCK(boot_lock);
  669. +static DEFINE_RAW_SPINLOCK(boot_lock);
  670. static void ux500_secondary_init(unsigned int cpu)
  671. {
  672. @@ -64,8 +64,8 @@
  673. /*
  674. * Synchronise with the boot thread.
  675. */
  676. - spin_lock(&boot_lock);
  677. - spin_unlock(&boot_lock);
  678. + raw_spin_lock(&boot_lock);
  679. + raw_spin_unlock(&boot_lock);
  680. }
  681. static int ux500_boot_secondary(unsigned int cpu, struct task_struct *idle)
  682. @@ -76,7 +76,7 @@
  683. * set synchronisation state between this boot processor
  684. * and the secondary one
  685. */
  686. - spin_lock(&boot_lock);
  687. + raw_spin_lock(&boot_lock);
  688. /*
  689. * The secondary processor is waiting to be released from
  690. @@ -97,7 +97,7 @@
  691. * now the secondary core is starting up let it run its
  692. * calibrations, then wait for it to finish
  693. */
  694. - spin_unlock(&boot_lock);
  695. + raw_spin_unlock(&boot_lock);
  696. return pen_release != -1 ? -ENOSYS : 0;
  697. }
  698. diff -Nur linux-4.1.6.orig/arch/arm/mm/fault.c linux-4.1.6/arch/arm/mm/fault.c
  699. --- linux-4.1.6.orig/arch/arm/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  700. +++ linux-4.1.6/arch/arm/mm/fault.c 2015-09-08 23:49:03.498378314 +0200
  701. @@ -276,7 +276,7 @@
  702. * If we're in an interrupt or have no user
  703. * context, we must not take the fault..
  704. */
  705. - if (in_atomic() || !mm)
  706. + if (faulthandler_disabled() || !mm)
  707. goto no_context;
  708. if (user_mode(regs))
  709. @@ -430,6 +430,9 @@
  710. if (addr < TASK_SIZE)
  711. return do_page_fault(addr, fsr, regs);
  712. + if (interrupts_enabled(regs))
  713. + local_irq_enable();
  714. +
  715. if (user_mode(regs))
  716. goto bad_area;
  717. @@ -497,6 +500,9 @@
  718. static int
  719. do_sect_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
  720. {
  721. + if (interrupts_enabled(regs))
  722. + local_irq_enable();
  723. +
  724. do_bad_area(addr, fsr, regs);
  725. return 0;
  726. }
  727. diff -Nur linux-4.1.6.orig/arch/arm/mm/highmem.c linux-4.1.6/arch/arm/mm/highmem.c
  728. --- linux-4.1.6.orig/arch/arm/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  729. +++ linux-4.1.6/arch/arm/mm/highmem.c 2015-09-08 23:49:03.498378314 +0200
  730. @@ -54,11 +54,13 @@
  731. void *kmap_atomic(struct page *page)
  732. {
  733. + pte_t pte = mk_pte(page, kmap_prot);
  734. unsigned int idx;
  735. unsigned long vaddr;
  736. void *kmap;
  737. int type;
  738. + preempt_disable_nort();
  739. pagefault_disable();
  740. if (!PageHighMem(page))
  741. return page_address(page);
  742. @@ -92,7 +94,10 @@
  743. * in place, so the contained TLB flush ensures the TLB is updated
  744. * with the new mapping.
  745. */
  746. - set_fixmap_pte(idx, mk_pte(page, kmap_prot));
  747. +#ifdef CONFIG_PREEMPT_RT_FULL
  748. + current->kmap_pte[type] = pte;
  749. +#endif
  750. + set_fixmap_pte(idx, pte);
  751. return (void *)vaddr;
  752. }
  753. @@ -109,27 +114,33 @@
  754. if (cache_is_vivt())
  755. __cpuc_flush_dcache_area((void *)vaddr, PAGE_SIZE);
  756. +#ifdef CONFIG_PREEMPT_RT_FULL
  757. + current->kmap_pte[type] = __pte(0);
  758. +#endif
  759. #ifdef CONFIG_DEBUG_HIGHMEM
  760. BUG_ON(vaddr != __fix_to_virt(idx));
  761. - set_fixmap_pte(idx, __pte(0));
  762. #else
  763. (void) idx; /* to kill a warning */
  764. #endif
  765. + set_fixmap_pte(idx, __pte(0));
  766. kmap_atomic_idx_pop();
  767. } else if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
  768. /* this address was obtained through kmap_high_get() */
  769. kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
  770. }
  771. pagefault_enable();
  772. + preempt_enable_nort();
  773. }
  774. EXPORT_SYMBOL(__kunmap_atomic);
  775. void *kmap_atomic_pfn(unsigned long pfn)
  776. {
  777. + pte_t pte = pfn_pte(pfn, kmap_prot);
  778. unsigned long vaddr;
  779. int idx, type;
  780. struct page *page = pfn_to_page(pfn);
  781. + preempt_disable_nort();
  782. pagefault_disable();
  783. if (!PageHighMem(page))
  784. return page_address(page);
  785. @@ -140,7 +151,10 @@
  786. #ifdef CONFIG_DEBUG_HIGHMEM
  787. BUG_ON(!pte_none(get_fixmap_pte(vaddr)));
  788. #endif
  789. - set_fixmap_pte(idx, pfn_pte(pfn, kmap_prot));
  790. +#ifdef CONFIG_PREEMPT_RT_FULL
  791. + current->kmap_pte[type] = pte;
  792. +#endif
  793. + set_fixmap_pte(idx, pte);
  794. return (void *)vaddr;
  795. }
  796. @@ -154,3 +168,28 @@
  797. return pte_page(get_fixmap_pte(vaddr));
  798. }
  799. +
  800. +#if defined CONFIG_PREEMPT_RT_FULL
  801. +void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  802. +{
  803. + int i;
  804. +
  805. + /*
  806. + * Clear @prev's kmap_atomic mappings
  807. + */
  808. + for (i = 0; i < prev_p->kmap_idx; i++) {
  809. + int idx = i + KM_TYPE_NR * smp_processor_id();
  810. +
  811. + set_fixmap_pte(idx, __pte(0));
  812. + }
  813. + /*
  814. + * Restore @next_p's kmap_atomic mappings
  815. + */
  816. + for (i = 0; i < next_p->kmap_idx; i++) {
  817. + int idx = i + KM_TYPE_NR * smp_processor_id();
  818. +
  819. + if (!pte_none(next_p->kmap_pte[i]))
  820. + set_fixmap_pte(idx, next_p->kmap_pte[i]);
  821. + }
  822. +}
  823. +#endif
  824. diff -Nur linux-4.1.6.orig/arch/arm/plat-versatile/platsmp.c linux-4.1.6/arch/arm/plat-versatile/platsmp.c
  825. --- linux-4.1.6.orig/arch/arm/plat-versatile/platsmp.c 2015-08-17 05:52:51.000000000 +0200
  826. +++ linux-4.1.6/arch/arm/plat-versatile/platsmp.c 2015-09-08 23:49:03.502377871 +0200
  827. @@ -30,7 +30,7 @@
  828. sync_cache_w(&pen_release);
  829. }
  830. -static DEFINE_SPINLOCK(boot_lock);
  831. +static DEFINE_RAW_SPINLOCK(boot_lock);
  832. void versatile_secondary_init(unsigned int cpu)
  833. {
  834. @@ -43,8 +43,8 @@
  835. /*
  836. * Synchronise with the boot thread.
  837. */
  838. - spin_lock(&boot_lock);
  839. - spin_unlock(&boot_lock);
  840. + raw_spin_lock(&boot_lock);
  841. + raw_spin_unlock(&boot_lock);
  842. }
  843. int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
  844. @@ -55,7 +55,7 @@
  845. * Set synchronisation state between this boot processor
  846. * and the secondary one
  847. */
  848. - spin_lock(&boot_lock);
  849. + raw_spin_lock(&boot_lock);
  850. /*
  851. * This is really belt and braces; we hold unintended secondary
  852. @@ -85,7 +85,7 @@
  853. * now the secondary core is starting up let it run its
  854. * calibrations, then wait for it to finish
  855. */
  856. - spin_unlock(&boot_lock);
  857. + raw_spin_unlock(&boot_lock);
  858. return pen_release != -1 ? -ENOSYS : 0;
  859. }
  860. diff -Nur linux-4.1.6.orig/arch/arm64/include/asm/futex.h linux-4.1.6/arch/arm64/include/asm/futex.h
  861. --- linux-4.1.6.orig/arch/arm64/include/asm/futex.h 2015-08-17 05:52:51.000000000 +0200
  862. +++ linux-4.1.6/arch/arm64/include/asm/futex.h 2015-09-08 23:49:03.502377871 +0200
  863. @@ -58,7 +58,7 @@
  864. if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
  865. return -EFAULT;
  866. - pagefault_disable(); /* implies preempt_disable() */
  867. + pagefault_disable();
  868. switch (op) {
  869. case FUTEX_OP_SET:
  870. @@ -85,7 +85,7 @@
  871. ret = -ENOSYS;
  872. }
  873. - pagefault_enable(); /* subsumes preempt_enable() */
  874. + pagefault_enable();
  875. if (!ret) {
  876. switch (cmp) {
  877. diff -Nur linux-4.1.6.orig/arch/arm64/include/asm/thread_info.h linux-4.1.6/arch/arm64/include/asm/thread_info.h
  878. --- linux-4.1.6.orig/arch/arm64/include/asm/thread_info.h 2015-08-17 05:52:51.000000000 +0200
  879. +++ linux-4.1.6/arch/arm64/include/asm/thread_info.h 2015-09-08 23:49:03.502377871 +0200
  880. @@ -47,6 +47,7 @@
  881. mm_segment_t addr_limit; /* address limit */
  882. struct task_struct *task; /* main task structure */
  883. int preempt_count; /* 0 => preemptable, <0 => bug */
  884. + int preempt_lazy_count; /* 0 => preemptable, <0 => bug */
  885. int cpu; /* cpu */
  886. };
  887. @@ -101,6 +102,7 @@
  888. #define TIF_NEED_RESCHED 1
  889. #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
  890. #define TIF_FOREIGN_FPSTATE 3 /* CPU's FP state is not current's */
  891. +#define TIF_NEED_RESCHED_LAZY 4
  892. #define TIF_NOHZ 7
  893. #define TIF_SYSCALL_TRACE 8
  894. #define TIF_SYSCALL_AUDIT 9
  895. @@ -117,6 +119,7 @@
  896. #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  897. #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  898. #define _TIF_FOREIGN_FPSTATE (1 << TIF_FOREIGN_FPSTATE)
  899. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  900. #define _TIF_NOHZ (1 << TIF_NOHZ)
  901. #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  902. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  903. diff -Nur linux-4.1.6.orig/arch/arm64/Kconfig linux-4.1.6/arch/arm64/Kconfig
  904. --- linux-4.1.6.orig/arch/arm64/Kconfig 2015-08-17 05:52:51.000000000 +0200
  905. +++ linux-4.1.6/arch/arm64/Kconfig 2015-09-08 23:49:03.502377871 +0200
  906. @@ -69,8 +69,10 @@
  907. select HAVE_PERF_REGS
  908. select HAVE_PERF_USER_STACK_DUMP
  909. select HAVE_RCU_TABLE_FREE
  910. + select HAVE_PREEMPT_LAZY
  911. select HAVE_SYSCALL_TRACEPOINTS
  912. select IRQ_DOMAIN
  913. + select IRQ_FORCED_THREADING
  914. select MODULES_USE_ELF_RELA
  915. select NO_BOOTMEM
  916. select OF
  917. diff -Nur linux-4.1.6.orig/arch/arm64/kernel/asm-offsets.c linux-4.1.6/arch/arm64/kernel/asm-offsets.c
  918. --- linux-4.1.6.orig/arch/arm64/kernel/asm-offsets.c 2015-08-17 05:52:51.000000000 +0200
  919. +++ linux-4.1.6/arch/arm64/kernel/asm-offsets.c 2015-09-08 23:49:03.502377871 +0200
  920. @@ -35,6 +35,7 @@
  921. BLANK();
  922. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  923. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  924. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  925. DEFINE(TI_ADDR_LIMIT, offsetof(struct thread_info, addr_limit));
  926. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  927. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  928. diff -Nur linux-4.1.6.orig/arch/arm64/kernel/entry.S linux-4.1.6/arch/arm64/kernel/entry.S
  929. --- linux-4.1.6.orig/arch/arm64/kernel/entry.S 2015-08-17 05:52:51.000000000 +0200
  930. +++ linux-4.1.6/arch/arm64/kernel/entry.S 2015-09-08 23:49:03.502377871 +0200
  931. @@ -367,11 +367,16 @@
  932. #ifdef CONFIG_PREEMPT
  933. get_thread_info tsk
  934. ldr w24, [tsk, #TI_PREEMPT] // get preempt count
  935. - cbnz w24, 1f // preempt count != 0
  936. + cbnz w24, 2f // preempt count != 0
  937. ldr x0, [tsk, #TI_FLAGS] // get flags
  938. - tbz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  939. - bl el1_preempt
  940. + tbnz x0, #TIF_NEED_RESCHED, 1f // needs rescheduling?
  941. +
  942. + ldr w24, [tsk, #TI_PREEMPT_LAZY] // get preempt lazy count
  943. + cbnz w24, 2f // preempt lazy count != 0
  944. + tbz x0, #TIF_NEED_RESCHED_LAZY, 2f // needs rescheduling?
  945. 1:
  946. + bl el1_preempt
  947. +2:
  948. #endif
  949. #ifdef CONFIG_TRACE_IRQFLAGS
  950. bl trace_hardirqs_on
  951. @@ -385,6 +390,7 @@
  952. 1: bl preempt_schedule_irq // irq en/disable is done inside
  953. ldr x0, [tsk, #TI_FLAGS] // get new tasks TI_FLAGS
  954. tbnz x0, #TIF_NEED_RESCHED, 1b // needs rescheduling?
  955. + tbnz x0, #TIF_NEED_RESCHED_LAZY, 1b // needs rescheduling?
  956. ret x24
  957. #endif
  958. @@ -622,6 +628,7 @@
  959. str x0, [sp, #S_X0] // returned x0
  960. work_pending:
  961. tbnz x1, #TIF_NEED_RESCHED, work_resched
  962. + tbnz x1, #TIF_NEED_RESCHED_LAZY, work_resched
  963. /* TIF_SIGPENDING, TIF_NOTIFY_RESUME or TIF_FOREIGN_FPSTATE case */
  964. ldr x2, [sp, #S_PSTATE]
  965. mov x0, sp // 'regs'
  966. diff -Nur linux-4.1.6.orig/arch/arm64/kernel/perf_event.c linux-4.1.6/arch/arm64/kernel/perf_event.c
  967. --- linux-4.1.6.orig/arch/arm64/kernel/perf_event.c 2015-08-17 05:52:51.000000000 +0200
  968. +++ linux-4.1.6/arch/arm64/kernel/perf_event.c 2015-09-08 23:49:03.502377871 +0200
  969. @@ -488,7 +488,7 @@
  970. }
  971. err = request_irq(irq, armpmu->handle_irq,
  972. - IRQF_NOBALANCING,
  973. + IRQF_NOBALANCING | IRQF_NO_THREAD,
  974. "arm-pmu", armpmu);
  975. if (err) {
  976. pr_err("unable to request IRQ%d for ARM PMU counters\n",
  977. diff -Nur linux-4.1.6.orig/arch/arm64/mm/fault.c linux-4.1.6/arch/arm64/mm/fault.c
  978. --- linux-4.1.6.orig/arch/arm64/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  979. +++ linux-4.1.6/arch/arm64/mm/fault.c 2015-09-08 23:49:03.502377871 +0200
  980. @@ -211,7 +211,7 @@
  981. * If we're in an interrupt or have no user context, we must not take
  982. * the fault.
  983. */
  984. - if (in_atomic() || !mm)
  985. + if (faulthandler_disabled() || !mm)
  986. goto no_context;
  987. if (user_mode(regs))
  988. diff -Nur linux-4.1.6.orig/arch/avr32/include/asm/uaccess.h linux-4.1.6/arch/avr32/include/asm/uaccess.h
  989. --- linux-4.1.6.orig/arch/avr32/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  990. +++ linux-4.1.6/arch/avr32/include/asm/uaccess.h 2015-09-08 23:49:03.502377871 +0200
  991. @@ -97,7 +97,8 @@
  992. * @x: Value to copy to user space.
  993. * @ptr: Destination address, in user space.
  994. *
  995. - * Context: User context only. This function may sleep.
  996. + * Context: User context only. This function may sleep if pagefaults are
  997. + * enabled.
  998. *
  999. * This macro copies a single simple value from kernel space to user
  1000. * space. It supports simple types like char and int, but not larger
  1001. @@ -116,7 +117,8 @@
  1002. * @x: Variable to store result.
  1003. * @ptr: Source address, in user space.
  1004. *
  1005. - * Context: User context only. This function may sleep.
  1006. + * Context: User context only. This function may sleep if pagefaults are
  1007. + * enabled.
  1008. *
  1009. * This macro copies a single simple variable from user space to kernel
  1010. * space. It supports simple types like char and int, but not larger
  1011. @@ -136,7 +138,8 @@
  1012. * @x: Value to copy to user space.
  1013. * @ptr: Destination address, in user space.
  1014. *
  1015. - * Context: User context only. This function may sleep.
  1016. + * Context: User context only. This function may sleep if pagefaults are
  1017. + * enabled.
  1018. *
  1019. * This macro copies a single simple value from kernel space to user
  1020. * space. It supports simple types like char and int, but not larger
  1021. @@ -158,7 +161,8 @@
  1022. * @x: Variable to store result.
  1023. * @ptr: Source address, in user space.
  1024. *
  1025. - * Context: User context only. This function may sleep.
  1026. + * Context: User context only. This function may sleep if pagefaults are
  1027. + * enabled.
  1028. *
  1029. * This macro copies a single simple variable from user space to kernel
  1030. * space. It supports simple types like char and int, but not larger
  1031. diff -Nur linux-4.1.6.orig/arch/avr32/mm/fault.c linux-4.1.6/arch/avr32/mm/fault.c
  1032. --- linux-4.1.6.orig/arch/avr32/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1033. +++ linux-4.1.6/arch/avr32/mm/fault.c 2015-09-08 23:49:03.502377871 +0200
  1034. @@ -14,11 +14,11 @@
  1035. #include <linux/pagemap.h>
  1036. #include <linux/kdebug.h>
  1037. #include <linux/kprobes.h>
  1038. +#include <linux/uaccess.h>
  1039. #include <asm/mmu_context.h>
  1040. #include <asm/sysreg.h>
  1041. #include <asm/tlb.h>
  1042. -#include <asm/uaccess.h>
  1043. #ifdef CONFIG_KPROBES
  1044. static inline int notify_page_fault(struct pt_regs *regs, int trap)
  1045. @@ -81,7 +81,7 @@
  1046. * If we're in an interrupt or have no user context, we must
  1047. * not take the fault...
  1048. */
  1049. - if (in_atomic() || !mm || regs->sr & SYSREG_BIT(GM))
  1050. + if (faulthandler_disabled() || !mm || regs->sr & SYSREG_BIT(GM))
  1051. goto no_context;
  1052. local_irq_enable();
  1053. diff -Nur linux-4.1.6.orig/arch/cris/mm/fault.c linux-4.1.6/arch/cris/mm/fault.c
  1054. --- linux-4.1.6.orig/arch/cris/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1055. +++ linux-4.1.6/arch/cris/mm/fault.c 2015-09-08 23:49:03.502377871 +0200
  1056. @@ -8,7 +8,7 @@
  1057. #include <linux/interrupt.h>
  1058. #include <linux/module.h>
  1059. #include <linux/wait.h>
  1060. -#include <asm/uaccess.h>
  1061. +#include <linux/uaccess.h>
  1062. #include <arch/system.h>
  1063. extern int find_fixup_code(struct pt_regs *);
  1064. @@ -109,11 +109,11 @@
  1065. info.si_code = SEGV_MAPERR;
  1066. /*
  1067. - * If we're in an interrupt or "atomic" operation or have no
  1068. + * If we're in an interrupt, have pagefaults disabled or have no
  1069. * user context, we must not take the fault.
  1070. */
  1071. - if (in_atomic() || !mm)
  1072. + if (faulthandler_disabled() || !mm)
  1073. goto no_context;
  1074. if (user_mode(regs))
  1075. diff -Nur linux-4.1.6.orig/arch/frv/mm/fault.c linux-4.1.6/arch/frv/mm/fault.c
  1076. --- linux-4.1.6.orig/arch/frv/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1077. +++ linux-4.1.6/arch/frv/mm/fault.c 2015-09-08 23:49:03.502377871 +0200
  1078. @@ -19,9 +19,9 @@
  1079. #include <linux/kernel.h>
  1080. #include <linux/ptrace.h>
  1081. #include <linux/hardirq.h>
  1082. +#include <linux/uaccess.h>
  1083. #include <asm/pgtable.h>
  1084. -#include <asm/uaccess.h>
  1085. #include <asm/gdb-stub.h>
  1086. /*****************************************************************************/
  1087. @@ -78,7 +78,7 @@
  1088. * If we're in an interrupt or have no user
  1089. * context, we must not take the fault..
  1090. */
  1091. - if (in_atomic() || !mm)
  1092. + if (faulthandler_disabled() || !mm)
  1093. goto no_context;
  1094. if (user_mode(__frame))
  1095. diff -Nur linux-4.1.6.orig/arch/frv/mm/highmem.c linux-4.1.6/arch/frv/mm/highmem.c
  1096. --- linux-4.1.6.orig/arch/frv/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  1097. +++ linux-4.1.6/arch/frv/mm/highmem.c 2015-09-08 23:49:03.502377871 +0200
  1098. @@ -42,6 +42,7 @@
  1099. unsigned long paddr;
  1100. int type;
  1101. + preempt_disable();
  1102. pagefault_disable();
  1103. type = kmap_atomic_idx_push();
  1104. paddr = page_to_phys(page);
  1105. @@ -85,5 +86,6 @@
  1106. }
  1107. kmap_atomic_idx_pop();
  1108. pagefault_enable();
  1109. + preempt_enable();
  1110. }
  1111. EXPORT_SYMBOL(__kunmap_atomic);
  1112. diff -Nur linux-4.1.6.orig/arch/hexagon/include/asm/uaccess.h linux-4.1.6/arch/hexagon/include/asm/uaccess.h
  1113. --- linux-4.1.6.orig/arch/hexagon/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  1114. +++ linux-4.1.6/arch/hexagon/include/asm/uaccess.h 2015-09-08 23:49:04.386279854 +0200
  1115. @@ -36,7 +36,8 @@
  1116. * @addr: User space pointer to start of block to check
  1117. * @size: Size of block to check
  1118. *
  1119. - * Context: User context only. This function may sleep.
  1120. + * Context: User context only. This function may sleep if pagefaults are
  1121. + * enabled.
  1122. *
  1123. * Checks if a pointer to a block of memory in user space is valid.
  1124. *
  1125. diff -Nur linux-4.1.6.orig/arch/ia64/mm/fault.c linux-4.1.6/arch/ia64/mm/fault.c
  1126. --- linux-4.1.6.orig/arch/ia64/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1127. +++ linux-4.1.6/arch/ia64/mm/fault.c 2015-09-08 23:49:04.658249697 +0200
  1128. @@ -11,10 +11,10 @@
  1129. #include <linux/kprobes.h>
  1130. #include <linux/kdebug.h>
  1131. #include <linux/prefetch.h>
  1132. +#include <linux/uaccess.h>
  1133. #include <asm/pgtable.h>
  1134. #include <asm/processor.h>
  1135. -#include <asm/uaccess.h>
  1136. extern int die(char *, struct pt_regs *, long);
  1137. @@ -96,7 +96,7 @@
  1138. /*
  1139. * If we're in an interrupt or have no user context, we must not take the fault..
  1140. */
  1141. - if (in_atomic() || !mm)
  1142. + if (faulthandler_disabled() || !mm)
  1143. goto no_context;
  1144. #ifdef CONFIG_VIRTUAL_MEM_MAP
  1145. diff -Nur linux-4.1.6.orig/arch/Kconfig linux-4.1.6/arch/Kconfig
  1146. --- linux-4.1.6.orig/arch/Kconfig 2015-08-17 05:52:51.000000000 +0200
  1147. +++ linux-4.1.6/arch/Kconfig 2015-09-08 23:49:03.498378314 +0200
  1148. @@ -6,6 +6,7 @@
  1149. tristate "OProfile system profiling"
  1150. depends on PROFILING
  1151. depends on HAVE_OPROFILE
  1152. + depends on !PREEMPT_RT_FULL
  1153. select RING_BUFFER
  1154. select RING_BUFFER_ALLOW_SWAP
  1155. help
  1156. diff -Nur linux-4.1.6.orig/arch/m32r/include/asm/uaccess.h linux-4.1.6/arch/m32r/include/asm/uaccess.h
  1157. --- linux-4.1.6.orig/arch/m32r/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  1158. +++ linux-4.1.6/arch/m32r/include/asm/uaccess.h 2015-09-08 23:49:04.658249697 +0200
  1159. @@ -91,7 +91,8 @@
  1160. * @addr: User space pointer to start of block to check
  1161. * @size: Size of block to check
  1162. *
  1163. - * Context: User context only. This function may sleep.
  1164. + * Context: User context only. This function may sleep if pagefaults are
  1165. + * enabled.
  1166. *
  1167. * Checks if a pointer to a block of memory in user space is valid.
  1168. *
  1169. @@ -155,7 +156,8 @@
  1170. * @x: Variable to store result.
  1171. * @ptr: Source address, in user space.
  1172. *
  1173. - * Context: User context only. This function may sleep.
  1174. + * Context: User context only. This function may sleep if pagefaults are
  1175. + * enabled.
  1176. *
  1177. * This macro copies a single simple variable from user space to kernel
  1178. * space. It supports simple types like char and int, but not larger
  1179. @@ -175,7 +177,8 @@
  1180. * @x: Value to copy to user space.
  1181. * @ptr: Destination address, in user space.
  1182. *
  1183. - * Context: User context only. This function may sleep.
  1184. + * Context: User context only. This function may sleep if pagefaults are
  1185. + * enabled.
  1186. *
  1187. * This macro copies a single simple value from kernel space to user
  1188. * space. It supports simple types like char and int, but not larger
  1189. @@ -194,7 +197,8 @@
  1190. * @x: Variable to store result.
  1191. * @ptr: Source address, in user space.
  1192. *
  1193. - * Context: User context only. This function may sleep.
  1194. + * Context: User context only. This function may sleep if pagefaults are
  1195. + * enabled.
  1196. *
  1197. * This macro copies a single simple variable from user space to kernel
  1198. * space. It supports simple types like char and int, but not larger
  1199. @@ -274,7 +278,8 @@
  1200. * @x: Value to copy to user space.
  1201. * @ptr: Destination address, in user space.
  1202. *
  1203. - * Context: User context only. This function may sleep.
  1204. + * Context: User context only. This function may sleep if pagefaults are
  1205. + * enabled.
  1206. *
  1207. * This macro copies a single simple value from kernel space to user
  1208. * space. It supports simple types like char and int, but not larger
  1209. @@ -568,7 +573,8 @@
  1210. * @from: Source address, in kernel space.
  1211. * @n: Number of bytes to copy.
  1212. *
  1213. - * Context: User context only. This function may sleep.
  1214. + * Context: User context only. This function may sleep if pagefaults are
  1215. + * enabled.
  1216. *
  1217. * Copy data from kernel space to user space. Caller must check
  1218. * the specified block with access_ok() before calling this function.
  1219. @@ -588,7 +594,8 @@
  1220. * @from: Source address, in kernel space.
  1221. * @n: Number of bytes to copy.
  1222. *
  1223. - * Context: User context only. This function may sleep.
  1224. + * Context: User context only. This function may sleep if pagefaults are
  1225. + * enabled.
  1226. *
  1227. * Copy data from kernel space to user space.
  1228. *
  1229. @@ -606,7 +613,8 @@
  1230. * @from: Source address, in user space.
  1231. * @n: Number of bytes to copy.
  1232. *
  1233. - * Context: User context only. This function may sleep.
  1234. + * Context: User context only. This function may sleep if pagefaults are
  1235. + * enabled.
  1236. *
  1237. * Copy data from user space to kernel space. Caller must check
  1238. * the specified block with access_ok() before calling this function.
  1239. @@ -626,7 +634,8 @@
  1240. * @from: Source address, in user space.
  1241. * @n: Number of bytes to copy.
  1242. *
  1243. - * Context: User context only. This function may sleep.
  1244. + * Context: User context only. This function may sleep if pagefaults are
  1245. + * enabled.
  1246. *
  1247. * Copy data from user space to kernel space.
  1248. *
  1249. @@ -677,7 +686,8 @@
  1250. * strlen_user: - Get the size of a string in user space.
  1251. * @str: The string to measure.
  1252. *
  1253. - * Context: User context only. This function may sleep.
  1254. + * Context: User context only. This function may sleep if pagefaults are
  1255. + * enabled.
  1256. *
  1257. * Get the size of a NUL-terminated string in user space.
  1258. *
  1259. diff -Nur linux-4.1.6.orig/arch/m32r/mm/fault.c linux-4.1.6/arch/m32r/mm/fault.c
  1260. --- linux-4.1.6.orig/arch/m32r/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1261. +++ linux-4.1.6/arch/m32r/mm/fault.c 2015-09-08 23:49:04.658249697 +0200
  1262. @@ -24,9 +24,9 @@
  1263. #include <linux/vt_kern.h> /* For unblank_screen() */
  1264. #include <linux/highmem.h>
  1265. #include <linux/module.h>
  1266. +#include <linux/uaccess.h>
  1267. #include <asm/m32r.h>
  1268. -#include <asm/uaccess.h>
  1269. #include <asm/hardirq.h>
  1270. #include <asm/mmu_context.h>
  1271. #include <asm/tlbflush.h>
  1272. @@ -111,10 +111,10 @@
  1273. mm = tsk->mm;
  1274. /*
  1275. - * If we're in an interrupt or have no user context or are running in an
  1276. - * atomic region then we must not take the fault..
  1277. + * If we're in an interrupt or have no user context or have pagefaults
  1278. + * disabled then we must not take the fault.
  1279. */
  1280. - if (in_atomic() || !mm)
  1281. + if (faulthandler_disabled() || !mm)
  1282. goto bad_area_nosemaphore;
  1283. if (error_code & ACE_USERMODE)
  1284. diff -Nur linux-4.1.6.orig/arch/m68k/mm/fault.c linux-4.1.6/arch/m68k/mm/fault.c
  1285. --- linux-4.1.6.orig/arch/m68k/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1286. +++ linux-4.1.6/arch/m68k/mm/fault.c 2015-09-08 23:49:04.658249697 +0200
  1287. @@ -10,10 +10,10 @@
  1288. #include <linux/ptrace.h>
  1289. #include <linux/interrupt.h>
  1290. #include <linux/module.h>
  1291. +#include <linux/uaccess.h>
  1292. #include <asm/setup.h>
  1293. #include <asm/traps.h>
  1294. -#include <asm/uaccess.h>
  1295. #include <asm/pgalloc.h>
  1296. extern void die_if_kernel(char *, struct pt_regs *, long);
  1297. @@ -81,7 +81,7 @@
  1298. * If we're in an interrupt or have no user
  1299. * context, we must not take the fault..
  1300. */
  1301. - if (in_atomic() || !mm)
  1302. + if (faulthandler_disabled() || !mm)
  1303. goto no_context;
  1304. if (user_mode(regs))
  1305. diff -Nur linux-4.1.6.orig/arch/metag/mm/fault.c linux-4.1.6/arch/metag/mm/fault.c
  1306. --- linux-4.1.6.orig/arch/metag/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1307. +++ linux-4.1.6/arch/metag/mm/fault.c 2015-09-08 23:49:04.658249697 +0200
  1308. @@ -105,7 +105,7 @@
  1309. mm = tsk->mm;
  1310. - if (in_atomic() || !mm)
  1311. + if (faulthandler_disabled() || !mm)
  1312. goto no_context;
  1313. if (user_mode(regs))
  1314. diff -Nur linux-4.1.6.orig/arch/metag/mm/highmem.c linux-4.1.6/arch/metag/mm/highmem.c
  1315. --- linux-4.1.6.orig/arch/metag/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  1316. +++ linux-4.1.6/arch/metag/mm/highmem.c 2015-09-08 23:49:04.662249253 +0200
  1317. @@ -43,7 +43,7 @@
  1318. unsigned long vaddr;
  1319. int type;
  1320. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1321. + preempt_disable();
  1322. pagefault_disable();
  1323. if (!PageHighMem(page))
  1324. return page_address(page);
  1325. @@ -82,6 +82,7 @@
  1326. }
  1327. pagefault_enable();
  1328. + preempt_enable();
  1329. }
  1330. EXPORT_SYMBOL(__kunmap_atomic);
  1331. @@ -95,6 +96,7 @@
  1332. unsigned long vaddr;
  1333. int type;
  1334. + preempt_disable();
  1335. pagefault_disable();
  1336. type = kmap_atomic_idx_push();
  1337. diff -Nur linux-4.1.6.orig/arch/microblaze/include/asm/uaccess.h linux-4.1.6/arch/microblaze/include/asm/uaccess.h
  1338. --- linux-4.1.6.orig/arch/microblaze/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  1339. +++ linux-4.1.6/arch/microblaze/include/asm/uaccess.h 2015-09-08 23:49:04.662249253 +0200
  1340. @@ -178,7 +178,8 @@
  1341. * @x: Variable to store result.
  1342. * @ptr: Source address, in user space.
  1343. *
  1344. - * Context: User context only. This function may sleep.
  1345. + * Context: User context only. This function may sleep if pagefaults are
  1346. + * enabled.
  1347. *
  1348. * This macro copies a single simple variable from user space to kernel
  1349. * space. It supports simple types like char and int, but not larger
  1350. @@ -290,7 +291,8 @@
  1351. * @x: Value to copy to user space.
  1352. * @ptr: Destination address, in user space.
  1353. *
  1354. - * Context: User context only. This function may sleep.
  1355. + * Context: User context only. This function may sleep if pagefaults are
  1356. + * enabled.
  1357. *
  1358. * This macro copies a single simple value from kernel space to user
  1359. * space. It supports simple types like char and int, but not larger
  1360. diff -Nur linux-4.1.6.orig/arch/microblaze/mm/fault.c linux-4.1.6/arch/microblaze/mm/fault.c
  1361. --- linux-4.1.6.orig/arch/microblaze/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1362. +++ linux-4.1.6/arch/microblaze/mm/fault.c 2015-09-08 23:49:04.670248364 +0200
  1363. @@ -107,14 +107,14 @@
  1364. if ((error_code & 0x13) == 0x13 || (error_code & 0x11) == 0x11)
  1365. is_write = 0;
  1366. - if (unlikely(in_atomic() || !mm)) {
  1367. + if (unlikely(faulthandler_disabled() || !mm)) {
  1368. if (kernel_mode(regs))
  1369. goto bad_area_nosemaphore;
  1370. - /* in_atomic() in user mode is really bad,
  1371. + /* faulthandler_disabled() in user mode is really bad,
  1372. as is current->mm == NULL. */
  1373. - pr_emerg("Page fault in user mode with in_atomic(), mm = %p\n",
  1374. - mm);
  1375. + pr_emerg("Page fault in user mode with faulthandler_disabled(), mm = %p\n",
  1376. + mm);
  1377. pr_emerg("r15 = %lx MSR = %lx\n",
  1378. regs->r15, regs->msr);
  1379. die("Weird page fault", regs, SIGSEGV);
  1380. diff -Nur linux-4.1.6.orig/arch/microblaze/mm/highmem.c linux-4.1.6/arch/microblaze/mm/highmem.c
  1381. --- linux-4.1.6.orig/arch/microblaze/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  1382. +++ linux-4.1.6/arch/microblaze/mm/highmem.c 2015-09-08 23:49:04.670248364 +0200
  1383. @@ -37,7 +37,7 @@
  1384. unsigned long vaddr;
  1385. int idx, type;
  1386. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1387. + preempt_disable();
  1388. pagefault_disable();
  1389. if (!PageHighMem(page))
  1390. return page_address(page);
  1391. @@ -63,6 +63,7 @@
  1392. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  1393. pagefault_enable();
  1394. + preempt_enable();
  1395. return;
  1396. }
  1397. @@ -84,5 +85,6 @@
  1398. #endif
  1399. kmap_atomic_idx_pop();
  1400. pagefault_enable();
  1401. + preempt_enable();
  1402. }
  1403. EXPORT_SYMBOL(__kunmap_atomic);
  1404. diff -Nur linux-4.1.6.orig/arch/mips/include/asm/uaccess.h linux-4.1.6/arch/mips/include/asm/uaccess.h
  1405. --- linux-4.1.6.orig/arch/mips/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  1406. +++ linux-4.1.6/arch/mips/include/asm/uaccess.h 2015-09-08 23:49:04.670248364 +0200
  1407. @@ -103,7 +103,8 @@
  1408. * @addr: User space pointer to start of block to check
  1409. * @size: Size of block to check
  1410. *
  1411. - * Context: User context only. This function may sleep.
  1412. + * Context: User context only. This function may sleep if pagefaults are
  1413. + * enabled.
  1414. *
  1415. * Checks if a pointer to a block of memory in user space is valid.
  1416. *
  1417. @@ -138,7 +139,8 @@
  1418. * @x: Value to copy to user space.
  1419. * @ptr: Destination address, in user space.
  1420. *
  1421. - * Context: User context only. This function may sleep.
  1422. + * Context: User context only. This function may sleep if pagefaults are
  1423. + * enabled.
  1424. *
  1425. * This macro copies a single simple value from kernel space to user
  1426. * space. It supports simple types like char and int, but not larger
  1427. @@ -157,7 +159,8 @@
  1428. * @x: Variable to store result.
  1429. * @ptr: Source address, in user space.
  1430. *
  1431. - * Context: User context only. This function may sleep.
  1432. + * Context: User context only. This function may sleep if pagefaults are
  1433. + * enabled.
  1434. *
  1435. * This macro copies a single simple variable from user space to kernel
  1436. * space. It supports simple types like char and int, but not larger
  1437. @@ -177,7 +180,8 @@
  1438. * @x: Value to copy to user space.
  1439. * @ptr: Destination address, in user space.
  1440. *
  1441. - * Context: User context only. This function may sleep.
  1442. + * Context: User context only. This function may sleep if pagefaults are
  1443. + * enabled.
  1444. *
  1445. * This macro copies a single simple value from kernel space to user
  1446. * space. It supports simple types like char and int, but not larger
  1447. @@ -199,7 +203,8 @@
  1448. * @x: Variable to store result.
  1449. * @ptr: Source address, in user space.
  1450. *
  1451. - * Context: User context only. This function may sleep.
  1452. + * Context: User context only. This function may sleep if pagefaults are
  1453. + * enabled.
  1454. *
  1455. * This macro copies a single simple variable from user space to kernel
  1456. * space. It supports simple types like char and int, but not larger
  1457. @@ -498,7 +503,8 @@
  1458. * @x: Value to copy to user space.
  1459. * @ptr: Destination address, in user space.
  1460. *
  1461. - * Context: User context only. This function may sleep.
  1462. + * Context: User context only. This function may sleep if pagefaults are
  1463. + * enabled.
  1464. *
  1465. * This macro copies a single simple value from kernel space to user
  1466. * space. It supports simple types like char and int, but not larger
  1467. @@ -517,7 +523,8 @@
  1468. * @x: Variable to store result.
  1469. * @ptr: Source address, in user space.
  1470. *
  1471. - * Context: User context only. This function may sleep.
  1472. + * Context: User context only. This function may sleep if pagefaults are
  1473. + * enabled.
  1474. *
  1475. * This macro copies a single simple variable from user space to kernel
  1476. * space. It supports simple types like char and int, but not larger
  1477. @@ -537,7 +544,8 @@
  1478. * @x: Value to copy to user space.
  1479. * @ptr: Destination address, in user space.
  1480. *
  1481. - * Context: User context only. This function may sleep.
  1482. + * Context: User context only. This function may sleep if pagefaults are
  1483. + * enabled.
  1484. *
  1485. * This macro copies a single simple value from kernel space to user
  1486. * space. It supports simple types like char and int, but not larger
  1487. @@ -559,7 +567,8 @@
  1488. * @x: Variable to store result.
  1489. * @ptr: Source address, in user space.
  1490. *
  1491. - * Context: User context only. This function may sleep.
  1492. + * Context: User context only. This function may sleep if pagefaults are
  1493. + * enabled.
  1494. *
  1495. * This macro copies a single simple variable from user space to kernel
  1496. * space. It supports simple types like char and int, but not larger
  1497. @@ -815,7 +824,8 @@
  1498. * @from: Source address, in kernel space.
  1499. * @n: Number of bytes to copy.
  1500. *
  1501. - * Context: User context only. This function may sleep.
  1502. + * Context: User context only. This function may sleep if pagefaults are
  1503. + * enabled.
  1504. *
  1505. * Copy data from kernel space to user space. Caller must check
  1506. * the specified block with access_ok() before calling this function.
  1507. @@ -888,7 +898,8 @@
  1508. * @from: Source address, in kernel space.
  1509. * @n: Number of bytes to copy.
  1510. *
  1511. - * Context: User context only. This function may sleep.
  1512. + * Context: User context only. This function may sleep if pagefaults are
  1513. + * enabled.
  1514. *
  1515. * Copy data from kernel space to user space.
  1516. *
  1517. @@ -1075,7 +1086,8 @@
  1518. * @from: Source address, in user space.
  1519. * @n: Number of bytes to copy.
  1520. *
  1521. - * Context: User context only. This function may sleep.
  1522. + * Context: User context only. This function may sleep if pagefaults are
  1523. + * enabled.
  1524. *
  1525. * Copy data from user space to kernel space. Caller must check
  1526. * the specified block with access_ok() before calling this function.
  1527. @@ -1107,7 +1119,8 @@
  1528. * @from: Source address, in user space.
  1529. * @n: Number of bytes to copy.
  1530. *
  1531. - * Context: User context only. This function may sleep.
  1532. + * Context: User context only. This function may sleep if pagefaults are
  1533. + * enabled.
  1534. *
  1535. * Copy data from user space to kernel space.
  1536. *
  1537. @@ -1329,7 +1342,8 @@
  1538. * strlen_user: - Get the size of a string in user space.
  1539. * @str: The string to measure.
  1540. *
  1541. - * Context: User context only. This function may sleep.
  1542. + * Context: User context only. This function may sleep if pagefaults are
  1543. + * enabled.
  1544. *
  1545. * Get the size of a NUL-terminated string in user space.
  1546. *
  1547. @@ -1398,7 +1412,8 @@
  1548. * strnlen_user: - Get the size of a string in user space.
  1549. * @str: The string to measure.
  1550. *
  1551. - * Context: User context only. This function may sleep.
  1552. + * Context: User context only. This function may sleep if pagefaults are
  1553. + * enabled.
  1554. *
  1555. * Get the size of a NUL-terminated string in user space.
  1556. *
  1557. diff -Nur linux-4.1.6.orig/arch/mips/Kconfig linux-4.1.6/arch/mips/Kconfig
  1558. --- linux-4.1.6.orig/arch/mips/Kconfig 2015-08-17 05:52:51.000000000 +0200
  1559. +++ linux-4.1.6/arch/mips/Kconfig 2015-09-08 23:49:04.670248364 +0200
  1560. @@ -2366,7 +2366,7 @@
  1561. #
  1562. config HIGHMEM
  1563. bool "High Memory Support"
  1564. - depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA
  1565. + depends on 32BIT && CPU_SUPPORTS_HIGHMEM && SYS_SUPPORTS_HIGHMEM && !CPU_MIPS32_3_5_EVA && !PREEMPT_RT_FULL
  1566. config CPU_SUPPORTS_HIGHMEM
  1567. bool
  1568. diff -Nur linux-4.1.6.orig/arch/mips/kernel/signal-common.h linux-4.1.6/arch/mips/kernel/signal-common.h
  1569. --- linux-4.1.6.orig/arch/mips/kernel/signal-common.h 2015-08-17 05:52:51.000000000 +0200
  1570. +++ linux-4.1.6/arch/mips/kernel/signal-common.h 2015-09-08 23:49:04.674247921 +0200
  1571. @@ -28,12 +28,7 @@
  1572. extern int fpcsr_pending(unsigned int __user *fpcsr);
  1573. /* Make sure we will not lose FPU ownership */
  1574. -#ifdef CONFIG_PREEMPT
  1575. -#define lock_fpu_owner() preempt_disable()
  1576. -#define unlock_fpu_owner() preempt_enable()
  1577. -#else
  1578. -#define lock_fpu_owner() pagefault_disable()
  1579. -#define unlock_fpu_owner() pagefault_enable()
  1580. -#endif
  1581. +#define lock_fpu_owner() ({ preempt_disable(); pagefault_disable(); })
  1582. +#define unlock_fpu_owner() ({ pagefault_enable(); preempt_enable(); })
  1583. #endif /* __SIGNAL_COMMON_H */
  1584. diff -Nur linux-4.1.6.orig/arch/mips/mm/fault.c linux-4.1.6/arch/mips/mm/fault.c
  1585. --- linux-4.1.6.orig/arch/mips/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1586. +++ linux-4.1.6/arch/mips/mm/fault.c 2015-09-08 23:49:04.674247921 +0200
  1587. @@ -21,10 +21,10 @@
  1588. #include <linux/module.h>
  1589. #include <linux/kprobes.h>
  1590. #include <linux/perf_event.h>
  1591. +#include <linux/uaccess.h>
  1592. #include <asm/branch.h>
  1593. #include <asm/mmu_context.h>
  1594. -#include <asm/uaccess.h>
  1595. #include <asm/ptrace.h>
  1596. #include <asm/highmem.h> /* For VMALLOC_END */
  1597. #include <linux/kdebug.h>
  1598. @@ -94,7 +94,7 @@
  1599. * If we're in an interrupt or have no user
  1600. * context, we must not take the fault..
  1601. */
  1602. - if (in_atomic() || !mm)
  1603. + if (faulthandler_disabled() || !mm)
  1604. goto bad_area_nosemaphore;
  1605. if (user_mode(regs))
  1606. diff -Nur linux-4.1.6.orig/arch/mips/mm/highmem.c linux-4.1.6/arch/mips/mm/highmem.c
  1607. --- linux-4.1.6.orig/arch/mips/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  1608. +++ linux-4.1.6/arch/mips/mm/highmem.c 2015-09-08 23:49:04.674247921 +0200
  1609. @@ -47,7 +47,7 @@
  1610. unsigned long vaddr;
  1611. int idx, type;
  1612. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  1613. + preempt_disable();
  1614. pagefault_disable();
  1615. if (!PageHighMem(page))
  1616. return page_address(page);
  1617. @@ -72,6 +72,7 @@
  1618. if (vaddr < FIXADDR_START) { // FIXME
  1619. pagefault_enable();
  1620. + preempt_enable();
  1621. return;
  1622. }
  1623. @@ -92,6 +93,7 @@
  1624. #endif
  1625. kmap_atomic_idx_pop();
  1626. pagefault_enable();
  1627. + preempt_enable();
  1628. }
  1629. EXPORT_SYMBOL(__kunmap_atomic);
  1630. @@ -104,6 +106,7 @@
  1631. unsigned long vaddr;
  1632. int idx, type;
  1633. + preempt_disable();
  1634. pagefault_disable();
  1635. type = kmap_atomic_idx_push();
  1636. diff -Nur linux-4.1.6.orig/arch/mips/mm/init.c linux-4.1.6/arch/mips/mm/init.c
  1637. --- linux-4.1.6.orig/arch/mips/mm/init.c 2015-08-17 05:52:51.000000000 +0200
  1638. +++ linux-4.1.6/arch/mips/mm/init.c 2015-09-08 23:49:04.674247921 +0200
  1639. @@ -90,6 +90,7 @@
  1640. BUG_ON(Page_dcache_dirty(page));
  1641. + preempt_disable();
  1642. pagefault_disable();
  1643. idx = (addr >> PAGE_SHIFT) & (FIX_N_COLOURS - 1);
  1644. idx += in_interrupt() ? FIX_N_COLOURS : 0;
  1645. @@ -152,6 +153,7 @@
  1646. write_c0_entryhi(old_ctx);
  1647. local_irq_restore(flags);
  1648. pagefault_enable();
  1649. + preempt_enable();
  1650. }
  1651. void copy_user_highpage(struct page *to, struct page *from,
  1652. diff -Nur linux-4.1.6.orig/arch/mn10300/include/asm/highmem.h linux-4.1.6/arch/mn10300/include/asm/highmem.h
  1653. --- linux-4.1.6.orig/arch/mn10300/include/asm/highmem.h 2015-08-17 05:52:51.000000000 +0200
  1654. +++ linux-4.1.6/arch/mn10300/include/asm/highmem.h 2015-09-08 23:49:04.674247921 +0200
  1655. @@ -75,6 +75,7 @@
  1656. unsigned long vaddr;
  1657. int idx, type;
  1658. + preempt_disable();
  1659. pagefault_disable();
  1660. if (page < highmem_start_page)
  1661. return page_address(page);
  1662. @@ -98,6 +99,7 @@
  1663. if (vaddr < FIXADDR_START) { /* FIXME */
  1664. pagefault_enable();
  1665. + preempt_enable();
  1666. return;
  1667. }
  1668. @@ -122,6 +124,7 @@
  1669. kmap_atomic_idx_pop();
  1670. pagefault_enable();
  1671. + preempt_enable();
  1672. }
  1673. #endif /* __KERNEL__ */
  1674. diff -Nur linux-4.1.6.orig/arch/mn10300/mm/fault.c linux-4.1.6/arch/mn10300/mm/fault.c
  1675. --- linux-4.1.6.orig/arch/mn10300/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1676. +++ linux-4.1.6/arch/mn10300/mm/fault.c 2015-09-08 23:49:04.674247921 +0200
  1677. @@ -23,8 +23,8 @@
  1678. #include <linux/interrupt.h>
  1679. #include <linux/init.h>
  1680. #include <linux/vt_kern.h> /* For unblank_screen() */
  1681. +#include <linux/uaccess.h>
  1682. -#include <asm/uaccess.h>
  1683. #include <asm/pgalloc.h>
  1684. #include <asm/hardirq.h>
  1685. #include <asm/cpu-regs.h>
  1686. @@ -168,7 +168,7 @@
  1687. * If we're in an interrupt or have no user
  1688. * context, we must not take the fault..
  1689. */
  1690. - if (in_atomic() || !mm)
  1691. + if (faulthandler_disabled() || !mm)
  1692. goto no_context;
  1693. if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
  1694. diff -Nur linux-4.1.6.orig/arch/nios2/mm/fault.c linux-4.1.6/arch/nios2/mm/fault.c
  1695. --- linux-4.1.6.orig/arch/nios2/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1696. +++ linux-4.1.6/arch/nios2/mm/fault.c 2015-09-08 23:49:04.674247921 +0200
  1697. @@ -77,7 +77,7 @@
  1698. * If we're in an interrupt or have no user
  1699. * context, we must not take the fault..
  1700. */
  1701. - if (in_atomic() || !mm)
  1702. + if (faulthandler_disabled() || !mm)
  1703. goto bad_area_nosemaphore;
  1704. if (user_mode(regs))
  1705. diff -Nur linux-4.1.6.orig/arch/parisc/include/asm/cacheflush.h linux-4.1.6/arch/parisc/include/asm/cacheflush.h
  1706. --- linux-4.1.6.orig/arch/parisc/include/asm/cacheflush.h 2015-08-17 05:52:51.000000000 +0200
  1707. +++ linux-4.1.6/arch/parisc/include/asm/cacheflush.h 2015-09-08 23:49:04.674247921 +0200
  1708. @@ -142,6 +142,7 @@
  1709. static inline void *kmap_atomic(struct page *page)
  1710. {
  1711. + preempt_disable();
  1712. pagefault_disable();
  1713. return page_address(page);
  1714. }
  1715. @@ -150,6 +151,7 @@
  1716. {
  1717. flush_kernel_dcache_page_addr(addr);
  1718. pagefault_enable();
  1719. + preempt_enable();
  1720. }
  1721. #define kmap_atomic_prot(page, prot) kmap_atomic(page)
  1722. diff -Nur linux-4.1.6.orig/arch/parisc/kernel/traps.c linux-4.1.6/arch/parisc/kernel/traps.c
  1723. --- linux-4.1.6.orig/arch/parisc/kernel/traps.c 2015-08-17 05:52:51.000000000 +0200
  1724. +++ linux-4.1.6/arch/parisc/kernel/traps.c 2015-09-08 23:49:04.678247479 +0200
  1725. @@ -26,9 +26,9 @@
  1726. #include <linux/console.h>
  1727. #include <linux/bug.h>
  1728. #include <linux/ratelimit.h>
  1729. +#include <linux/uaccess.h>
  1730. #include <asm/assembly.h>
  1731. -#include <asm/uaccess.h>
  1732. #include <asm/io.h>
  1733. #include <asm/irq.h>
  1734. #include <asm/traps.h>
  1735. @@ -796,7 +796,7 @@
  1736. * unless pagefault_disable() was called before.
  1737. */
  1738. - if (fault_space == 0 && !in_atomic())
  1739. + if (fault_space == 0 && !faulthandler_disabled())
  1740. {
  1741. pdc_chassis_send_status(PDC_CHASSIS_DIRECT_PANIC);
  1742. parisc_terminate("Kernel Fault", regs, code, fault_address);
  1743. diff -Nur linux-4.1.6.orig/arch/parisc/mm/fault.c linux-4.1.6/arch/parisc/mm/fault.c
  1744. --- linux-4.1.6.orig/arch/parisc/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  1745. +++ linux-4.1.6/arch/parisc/mm/fault.c 2015-09-08 23:49:04.678247479 +0200
  1746. @@ -15,8 +15,8 @@
  1747. #include <linux/sched.h>
  1748. #include <linux/interrupt.h>
  1749. #include <linux/module.h>
  1750. +#include <linux/uaccess.h>
  1751. -#include <asm/uaccess.h>
  1752. #include <asm/traps.h>
  1753. /* Various important other fields */
  1754. @@ -207,7 +207,7 @@
  1755. int fault;
  1756. unsigned int flags;
  1757. - if (in_atomic())
  1758. + if (pagefault_disabled())
  1759. goto no_context;
  1760. tsk = current;
  1761. diff -Nur linux-4.1.6.orig/arch/powerpc/include/asm/kvm_host.h linux-4.1.6/arch/powerpc/include/asm/kvm_host.h
  1762. --- linux-4.1.6.orig/arch/powerpc/include/asm/kvm_host.h 2015-08-17 05:52:51.000000000 +0200
  1763. +++ linux-4.1.6/arch/powerpc/include/asm/kvm_host.h 2015-09-08 23:49:04.810232841 +0200
  1764. @@ -280,7 +280,7 @@
  1765. u8 in_guest;
  1766. struct list_head runnable_threads;
  1767. spinlock_t lock;
  1768. - wait_queue_head_t wq;
  1769. + struct swait_head wq;
  1770. spinlock_t stoltb_lock; /* protects stolen_tb and preempt_tb */
  1771. u64 stolen_tb;
  1772. u64 preempt_tb;
  1773. @@ -613,7 +613,7 @@
  1774. u8 prodded;
  1775. u32 last_inst;
  1776. - wait_queue_head_t *wqp;
  1777. + struct swait_head *wqp;
  1778. struct kvmppc_vcore *vcore;
  1779. int ret;
  1780. int trap;
  1781. diff -Nur linux-4.1.6.orig/arch/powerpc/include/asm/thread_info.h linux-4.1.6/arch/powerpc/include/asm/thread_info.h
  1782. --- linux-4.1.6.orig/arch/powerpc/include/asm/thread_info.h 2015-08-17 05:52:51.000000000 +0200
  1783. +++ linux-4.1.6/arch/powerpc/include/asm/thread_info.h 2015-09-08 23:49:04.810232841 +0200
  1784. @@ -42,6 +42,8 @@
  1785. int cpu; /* cpu we're on */
  1786. int preempt_count; /* 0 => preemptable,
  1787. <0 => BUG */
  1788. + int preempt_lazy_count; /* 0 => preemptable,
  1789. + <0 => BUG */
  1790. unsigned long local_flags; /* private flags for thread */
  1791. /* low level flags - has atomic operations done on it */
  1792. @@ -82,8 +84,7 @@
  1793. #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  1794. #define TIF_SIGPENDING 1 /* signal pending */
  1795. #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
  1796. -#define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
  1797. - TIF_NEED_RESCHED */
  1798. +#define TIF_NEED_RESCHED_LAZY 3 /* lazy rescheduling necessary */
  1799. #define TIF_32BIT 4 /* 32 bit binary */
  1800. #define TIF_RESTORE_TM 5 /* need to restore TM FP/VEC/VSX */
  1801. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  1802. @@ -101,6 +102,8 @@
  1803. #if defined(CONFIG_PPC64)
  1804. #define TIF_ELF2ABI 18 /* function descriptors must die! */
  1805. #endif
  1806. +#define TIF_POLLING_NRFLAG 19 /* true if poll_idle() is polling
  1807. + TIF_NEED_RESCHED */
  1808. /* as above, but as bit values */
  1809. #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
  1810. @@ -119,14 +122,16 @@
  1811. #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
  1812. #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
  1813. #define _TIF_NOHZ (1<<TIF_NOHZ)
  1814. +#define _TIF_NEED_RESCHED_LAZY (1<<TIF_NEED_RESCHED_LAZY)
  1815. #define _TIF_SYSCALL_DOTRACE (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
  1816. _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
  1817. _TIF_NOHZ)
  1818. #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
  1819. _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
  1820. - _TIF_RESTORE_TM)
  1821. + _TIF_RESTORE_TM | _TIF_NEED_RESCHED_LAZY)
  1822. #define _TIF_PERSYSCALL_MASK (_TIF_RESTOREALL|_TIF_NOERROR)
  1823. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  1824. /* Bits in local_flags */
  1825. /* Don't move TLF_NAPPING without adjusting the code in entry_32.S */
  1826. diff -Nur linux-4.1.6.orig/arch/powerpc/Kconfig linux-4.1.6/arch/powerpc/Kconfig
  1827. --- linux-4.1.6.orig/arch/powerpc/Kconfig 2015-08-17 05:52:51.000000000 +0200
  1828. +++ linux-4.1.6/arch/powerpc/Kconfig 2015-09-08 23:49:04.810232841 +0200
  1829. @@ -60,10 +60,11 @@
  1830. config RWSEM_GENERIC_SPINLOCK
  1831. bool
  1832. + default y if PREEMPT_RT_FULL
  1833. config RWSEM_XCHGADD_ALGORITHM
  1834. bool
  1835. - default y
  1836. + default y if !PREEMPT_RT_FULL
  1837. config GENERIC_LOCKBREAK
  1838. bool
  1839. @@ -138,6 +139,7 @@
  1840. select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
  1841. select GENERIC_STRNCPY_FROM_USER
  1842. select GENERIC_STRNLEN_USER
  1843. + select HAVE_PREEMPT_LAZY
  1844. select HAVE_MOD_ARCH_SPECIFIC
  1845. select MODULES_USE_ELF_RELA
  1846. select CLONE_BACKWARDS
  1847. @@ -312,7 +314,7 @@
  1848. config HIGHMEM
  1849. bool "High memory support"
  1850. - depends on PPC32
  1851. + depends on PPC32 && !PREEMPT_RT_FULL
  1852. source kernel/Kconfig.hz
  1853. source kernel/Kconfig.preempt
  1854. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/asm-offsets.c linux-4.1.6/arch/powerpc/kernel/asm-offsets.c
  1855. --- linux-4.1.6.orig/arch/powerpc/kernel/asm-offsets.c 2015-08-17 05:52:51.000000000 +0200
  1856. +++ linux-4.1.6/arch/powerpc/kernel/asm-offsets.c 2015-09-08 23:49:04.810232841 +0200
  1857. @@ -160,6 +160,7 @@
  1858. DEFINE(TI_FLAGS, offsetof(struct thread_info, flags));
  1859. DEFINE(TI_LOCAL_FLAGS, offsetof(struct thread_info, local_flags));
  1860. DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count));
  1861. + DEFINE(TI_PREEMPT_LAZY, offsetof(struct thread_info, preempt_lazy_count));
  1862. DEFINE(TI_TASK, offsetof(struct thread_info, task));
  1863. DEFINE(TI_CPU, offsetof(struct thread_info, cpu));
  1864. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/entry_32.S linux-4.1.6/arch/powerpc/kernel/entry_32.S
  1865. --- linux-4.1.6.orig/arch/powerpc/kernel/entry_32.S 2015-08-17 05:52:51.000000000 +0200
  1866. +++ linux-4.1.6/arch/powerpc/kernel/entry_32.S 2015-09-08 23:49:04.810232841 +0200
  1867. @@ -813,7 +813,14 @@
  1868. cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1869. bne restore
  1870. andi. r8,r8,_TIF_NEED_RESCHED
  1871. + bne+ 1f
  1872. + lwz r0,TI_PREEMPT_LAZY(r9)
  1873. + cmpwi 0,r0,0 /* if non-zero, just restore regs and return */
  1874. + bne restore
  1875. + lwz r0,TI_FLAGS(r9)
  1876. + andi. r0,r0,_TIF_NEED_RESCHED_LAZY
  1877. beq+ restore
  1878. +1:
  1879. lwz r3,_MSR(r1)
  1880. andi. r0,r3,MSR_EE /* interrupts off? */
  1881. beq restore /* don't schedule if so */
  1882. @@ -824,11 +831,11 @@
  1883. */
  1884. bl trace_hardirqs_off
  1885. #endif
  1886. -1: bl preempt_schedule_irq
  1887. +2: bl preempt_schedule_irq
  1888. CURRENT_THREAD_INFO(r9, r1)
  1889. lwz r3,TI_FLAGS(r9)
  1890. - andi. r0,r3,_TIF_NEED_RESCHED
  1891. - bne- 1b
  1892. + andi. r0,r3,_TIF_NEED_RESCHED_MASK
  1893. + bne- 2b
  1894. #ifdef CONFIG_TRACE_IRQFLAGS
  1895. /* And now, to properly rebalance the above, we tell lockdep they
  1896. * are being turned back on, which will happen when we return
  1897. @@ -1149,7 +1156,7 @@
  1898. #endif /* !(CONFIG_4xx || CONFIG_BOOKE) */
  1899. do_work: /* r10 contains MSR_KERNEL here */
  1900. - andi. r0,r9,_TIF_NEED_RESCHED
  1901. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1902. beq do_user_signal
  1903. do_resched: /* r10 contains MSR_KERNEL here */
  1904. @@ -1170,7 +1177,7 @@
  1905. MTMSRD(r10) /* disable interrupts */
  1906. CURRENT_THREAD_INFO(r9, r1)
  1907. lwz r9,TI_FLAGS(r9)
  1908. - andi. r0,r9,_TIF_NEED_RESCHED
  1909. + andi. r0,r9,_TIF_NEED_RESCHED_MASK
  1910. bne- do_resched
  1911. andi. r0,r9,_TIF_USER_WORK_MASK
  1912. beq restore_user
  1913. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/entry_64.S linux-4.1.6/arch/powerpc/kernel/entry_64.S
  1914. --- linux-4.1.6.orig/arch/powerpc/kernel/entry_64.S 2015-08-17 05:52:51.000000000 +0200
  1915. +++ linux-4.1.6/arch/powerpc/kernel/entry_64.S 2015-09-08 23:49:04.818231956 +0200
  1916. @@ -636,7 +636,7 @@
  1917. #else
  1918. beq restore
  1919. #endif
  1920. -1: andi. r0,r4,_TIF_NEED_RESCHED
  1921. +1: andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1922. beq 2f
  1923. bl restore_interrupts
  1924. SCHEDULE_USER
  1925. @@ -698,10 +698,18 @@
  1926. #ifdef CONFIG_PREEMPT
  1927. /* Check if we need to preempt */
  1928. + lwz r8,TI_PREEMPT(r9)
  1929. + cmpwi 0,r8,0 /* if non-zero, just restore regs and return */
  1930. + bne restore
  1931. andi. r0,r4,_TIF_NEED_RESCHED
  1932. + bne+ check_count
  1933. +
  1934. + andi. r0,r4,_TIF_NEED_RESCHED_LAZY
  1935. beq+ restore
  1936. + lwz r8,TI_PREEMPT_LAZY(r9)
  1937. +
  1938. /* Check that preempt_count() == 0 and interrupts are enabled */
  1939. - lwz r8,TI_PREEMPT(r9)
  1940. +check_count:
  1941. cmpwi cr1,r8,0
  1942. ld r0,SOFTE(r1)
  1943. cmpdi r0,0
  1944. @@ -718,7 +726,7 @@
  1945. /* Re-test flags and eventually loop */
  1946. CURRENT_THREAD_INFO(r9, r1)
  1947. ld r4,TI_FLAGS(r9)
  1948. - andi. r0,r4,_TIF_NEED_RESCHED
  1949. + andi. r0,r4,_TIF_NEED_RESCHED_MASK
  1950. bne 1b
  1951. /*
  1952. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/irq.c linux-4.1.6/arch/powerpc/kernel/irq.c
  1953. --- linux-4.1.6.orig/arch/powerpc/kernel/irq.c 2015-08-17 05:52:51.000000000 +0200
  1954. +++ linux-4.1.6/arch/powerpc/kernel/irq.c 2015-09-08 23:49:04.818231956 +0200
  1955. @@ -614,6 +614,7 @@
  1956. }
  1957. }
  1958. +#ifndef CONFIG_PREEMPT_RT_FULL
  1959. void do_softirq_own_stack(void)
  1960. {
  1961. struct thread_info *curtp, *irqtp;
  1962. @@ -631,6 +632,7 @@
  1963. if (irqtp->flags)
  1964. set_bits(irqtp->flags, &curtp->flags);
  1965. }
  1966. +#endif
  1967. irq_hw_number_t virq_to_hw(unsigned int virq)
  1968. {
  1969. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/misc_32.S linux-4.1.6/arch/powerpc/kernel/misc_32.S
  1970. --- linux-4.1.6.orig/arch/powerpc/kernel/misc_32.S 2015-08-17 05:52:51.000000000 +0200
  1971. +++ linux-4.1.6/arch/powerpc/kernel/misc_32.S 2015-09-08 23:49:04.818231956 +0200
  1972. @@ -40,6 +40,7 @@
  1973. * We store the saved ksp_limit in the unused part
  1974. * of the STACK_FRAME_OVERHEAD
  1975. */
  1976. +#ifndef CONFIG_PREEMPT_RT_FULL
  1977. _GLOBAL(call_do_softirq)
  1978. mflr r0
  1979. stw r0,4(r1)
  1980. @@ -56,6 +57,7 @@
  1981. stw r10,THREAD+KSP_LIMIT(r2)
  1982. mtlr r0
  1983. blr
  1984. +#endif
  1985. /*
  1986. * void call_do_irq(struct pt_regs *regs, struct thread_info *irqtp);
  1987. diff -Nur linux-4.1.6.orig/arch/powerpc/kernel/misc_64.S linux-4.1.6/arch/powerpc/kernel/misc_64.S
  1988. --- linux-4.1.6.orig/arch/powerpc/kernel/misc_64.S 2015-08-17 05:52:51.000000000 +0200
  1989. +++ linux-4.1.6/arch/powerpc/kernel/misc_64.S 2015-09-08 23:49:04.822231513 +0200
  1990. @@ -29,6 +29,7 @@
  1991. .text
  1992. +#ifndef CONFIG_PREEMPT_RT_FULL
  1993. _GLOBAL(call_do_softirq)
  1994. mflr r0
  1995. std r0,16(r1)
  1996. @@ -39,6 +40,7 @@
  1997. ld r0,16(r1)
  1998. mtlr r0
  1999. blr
  2000. +#endif
  2001. _GLOBAL(call_do_irq)
  2002. mflr r0
  2003. diff -Nur linux-4.1.6.orig/arch/powerpc/kvm/book3s_hv.c linux-4.1.6/arch/powerpc/kvm/book3s_hv.c
  2004. --- linux-4.1.6.orig/arch/powerpc/kvm/book3s_hv.c 2015-08-17 05:52:51.000000000 +0200
  2005. +++ linux-4.1.6/arch/powerpc/kvm/book3s_hv.c 2015-09-08 23:49:04.826231069 +0200
  2006. @@ -115,11 +115,11 @@
  2007. static void kvmppc_fast_vcpu_kick_hv(struct kvm_vcpu *vcpu)
  2008. {
  2009. int cpu = vcpu->cpu;
  2010. - wait_queue_head_t *wqp;
  2011. + struct swait_head *wqp;
  2012. wqp = kvm_arch_vcpu_wq(vcpu);
  2013. - if (waitqueue_active(wqp)) {
  2014. - wake_up_interruptible(wqp);
  2015. + if (swaitqueue_active(wqp)) {
  2016. + swait_wake_interruptible(wqp);
  2017. ++vcpu->stat.halt_wakeup;
  2018. }
  2019. @@ -686,8 +686,8 @@
  2020. tvcpu->arch.prodded = 1;
  2021. smp_mb();
  2022. if (vcpu->arch.ceded) {
  2023. - if (waitqueue_active(&vcpu->wq)) {
  2024. - wake_up_interruptible(&vcpu->wq);
  2025. + if (swaitqueue_active(&vcpu->wq)) {
  2026. + swait_wake_interruptible(&vcpu->wq);
  2027. vcpu->stat.halt_wakeup++;
  2028. }
  2029. }
  2030. @@ -1426,7 +1426,7 @@
  2031. INIT_LIST_HEAD(&vcore->runnable_threads);
  2032. spin_lock_init(&vcore->lock);
  2033. spin_lock_init(&vcore->stoltb_lock);
  2034. - init_waitqueue_head(&vcore->wq);
  2035. + init_swait_head(&vcore->wq);
  2036. vcore->preempt_tb = TB_NIL;
  2037. vcore->lpcr = kvm->arch.lpcr;
  2038. vcore->first_vcpuid = core * threads_per_subcore;
  2039. @@ -2073,10 +2073,9 @@
  2040. {
  2041. struct kvm_vcpu *vcpu;
  2042. int do_sleep = 1;
  2043. + DEFINE_SWAITER(wait);
  2044. - DEFINE_WAIT(wait);
  2045. -
  2046. - prepare_to_wait(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  2047. + swait_prepare(&vc->wq, &wait, TASK_INTERRUPTIBLE);
  2048. /*
  2049. * Check one last time for pending exceptions and ceded state after
  2050. @@ -2090,7 +2089,7 @@
  2051. }
  2052. if (!do_sleep) {
  2053. - finish_wait(&vc->wq, &wait);
  2054. + swait_finish(&vc->wq, &wait);
  2055. return;
  2056. }
  2057. @@ -2098,7 +2097,7 @@
  2058. trace_kvmppc_vcore_blocked(vc, 0);
  2059. spin_unlock(&vc->lock);
  2060. schedule();
  2061. - finish_wait(&vc->wq, &wait);
  2062. + swait_finish(&vc->wq, &wait);
  2063. spin_lock(&vc->lock);
  2064. vc->vcore_state = VCORE_INACTIVE;
  2065. trace_kvmppc_vcore_blocked(vc, 1);
  2066. @@ -2142,7 +2141,7 @@
  2067. kvmppc_start_thread(vcpu);
  2068. trace_kvm_guest_enter(vcpu);
  2069. } else if (vc->vcore_state == VCORE_SLEEPING) {
  2070. - wake_up(&vc->wq);
  2071. + swait_wake(&vc->wq);
  2072. }
  2073. }
  2074. diff -Nur linux-4.1.6.orig/arch/powerpc/kvm/Kconfig linux-4.1.6/arch/powerpc/kvm/Kconfig
  2075. --- linux-4.1.6.orig/arch/powerpc/kvm/Kconfig 2015-08-17 05:52:51.000000000 +0200
  2076. +++ linux-4.1.6/arch/powerpc/kvm/Kconfig 2015-09-08 23:49:04.822231513 +0200
  2077. @@ -172,6 +172,7 @@
  2078. config KVM_MPIC
  2079. bool "KVM in-kernel MPIC emulation"
  2080. depends on KVM && E500
  2081. + depends on !PREEMPT_RT_FULL
  2082. select HAVE_KVM_IRQCHIP
  2083. select HAVE_KVM_IRQFD
  2084. select HAVE_KVM_IRQ_ROUTING
  2085. diff -Nur linux-4.1.6.orig/arch/powerpc/mm/fault.c linux-4.1.6/arch/powerpc/mm/fault.c
  2086. --- linux-4.1.6.orig/arch/powerpc/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2087. +++ linux-4.1.6/arch/powerpc/mm/fault.c 2015-09-08 23:49:05.246184500 +0200
  2088. @@ -33,13 +33,13 @@
  2089. #include <linux/ratelimit.h>
  2090. #include <linux/context_tracking.h>
  2091. #include <linux/hugetlb.h>
  2092. +#include <linux/uaccess.h>
  2093. #include <asm/firmware.h>
  2094. #include <asm/page.h>
  2095. #include <asm/pgtable.h>
  2096. #include <asm/mmu.h>
  2097. #include <asm/mmu_context.h>
  2098. -#include <asm/uaccess.h>
  2099. #include <asm/tlbflush.h>
  2100. #include <asm/siginfo.h>
  2101. #include <asm/debug.h>
  2102. @@ -272,15 +272,16 @@
  2103. if (!arch_irq_disabled_regs(regs))
  2104. local_irq_enable();
  2105. - if (in_atomic() || mm == NULL) {
  2106. + if (faulthandler_disabled() || mm == NULL) {
  2107. if (!user_mode(regs)) {
  2108. rc = SIGSEGV;
  2109. goto bail;
  2110. }
  2111. - /* in_atomic() in user mode is really bad,
  2112. + /* faulthandler_disabled() in user mode is really bad,
  2113. as is current->mm == NULL. */
  2114. printk(KERN_EMERG "Page fault in user mode with "
  2115. - "in_atomic() = %d mm = %p\n", in_atomic(), mm);
  2116. + "faulthandler_disabled() = %d mm = %p\n",
  2117. + faulthandler_disabled(), mm);
  2118. printk(KERN_EMERG "NIP = %lx MSR = %lx\n",
  2119. regs->nip, regs->msr);
  2120. die("Weird page fault", regs, SIGSEGV);
  2121. diff -Nur linux-4.1.6.orig/arch/powerpc/mm/highmem.c linux-4.1.6/arch/powerpc/mm/highmem.c
  2122. --- linux-4.1.6.orig/arch/powerpc/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  2123. +++ linux-4.1.6/arch/powerpc/mm/highmem.c 2015-09-08 23:49:05.250184055 +0200
  2124. @@ -34,7 +34,7 @@
  2125. unsigned long vaddr;
  2126. int idx, type;
  2127. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2128. + preempt_disable();
  2129. pagefault_disable();
  2130. if (!PageHighMem(page))
  2131. return page_address(page);
  2132. @@ -59,6 +59,7 @@
  2133. if (vaddr < __fix_to_virt(FIX_KMAP_END)) {
  2134. pagefault_enable();
  2135. + preempt_enable();
  2136. return;
  2137. }
  2138. @@ -82,5 +83,6 @@
  2139. kmap_atomic_idx_pop();
  2140. pagefault_enable();
  2141. + preempt_enable();
  2142. }
  2143. EXPORT_SYMBOL(__kunmap_atomic);
  2144. diff -Nur linux-4.1.6.orig/arch/powerpc/platforms/ps3/device-init.c linux-4.1.6/arch/powerpc/platforms/ps3/device-init.c
  2145. --- linux-4.1.6.orig/arch/powerpc/platforms/ps3/device-init.c 2015-08-17 05:52:51.000000000 +0200
  2146. +++ linux-4.1.6/arch/powerpc/platforms/ps3/device-init.c 2015-09-08 23:49:05.250184055 +0200
  2147. @@ -752,7 +752,7 @@
  2148. }
  2149. pr_debug("%s:%u: notification %s issued\n", __func__, __LINE__, op);
  2150. - res = wait_event_interruptible(dev->done.wait,
  2151. + res = swait_event_interruptible(dev->done.wait,
  2152. dev->done.done || kthread_should_stop());
  2153. if (kthread_should_stop())
  2154. res = -EINTR;
  2155. diff -Nur linux-4.1.6.orig/arch/s390/include/asm/kvm_host.h linux-4.1.6/arch/s390/include/asm/kvm_host.h
  2156. --- linux-4.1.6.orig/arch/s390/include/asm/kvm_host.h 2015-08-17 05:52:51.000000000 +0200
  2157. +++ linux-4.1.6/arch/s390/include/asm/kvm_host.h 2015-09-08 23:49:05.250184055 +0200
  2158. @@ -419,7 +419,7 @@
  2159. struct kvm_s390_local_interrupt {
  2160. spinlock_t lock;
  2161. struct kvm_s390_float_interrupt *float_int;
  2162. - wait_queue_head_t *wq;
  2163. + struct swait_head *wq;
  2164. atomic_t *cpuflags;
  2165. DECLARE_BITMAP(sigp_emerg_pending, KVM_MAX_VCPUS);
  2166. struct kvm_s390_irq_payload irq;
  2167. diff -Nur linux-4.1.6.orig/arch/s390/include/asm/uaccess.h linux-4.1.6/arch/s390/include/asm/uaccess.h
  2168. --- linux-4.1.6.orig/arch/s390/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  2169. +++ linux-4.1.6/arch/s390/include/asm/uaccess.h 2015-09-08 23:49:05.250184055 +0200
  2170. @@ -98,7 +98,8 @@
  2171. * @from: Source address, in user space.
  2172. * @n: Number of bytes to copy.
  2173. *
  2174. - * Context: User context only. This function may sleep.
  2175. + * Context: User context only. This function may sleep if pagefaults are
  2176. + * enabled.
  2177. *
  2178. * Copy data from user space to kernel space. Caller must check
  2179. * the specified block with access_ok() before calling this function.
  2180. @@ -118,7 +119,8 @@
  2181. * @from: Source address, in kernel space.
  2182. * @n: Number of bytes to copy.
  2183. *
  2184. - * Context: User context only. This function may sleep.
  2185. + * Context: User context only. This function may sleep if pagefaults are
  2186. + * enabled.
  2187. *
  2188. * Copy data from kernel space to user space. Caller must check
  2189. * the specified block with access_ok() before calling this function.
  2190. @@ -264,7 +266,8 @@
  2191. * @from: Source address, in kernel space.
  2192. * @n: Number of bytes to copy.
  2193. *
  2194. - * Context: User context only. This function may sleep.
  2195. + * Context: User context only. This function may sleep if pagefaults are
  2196. + * enabled.
  2197. *
  2198. * Copy data from kernel space to user space.
  2199. *
  2200. @@ -290,7 +293,8 @@
  2201. * @from: Source address, in user space.
  2202. * @n: Number of bytes to copy.
  2203. *
  2204. - * Context: User context only. This function may sleep.
  2205. + * Context: User context only. This function may sleep if pagefaults are
  2206. + * enabled.
  2207. *
  2208. * Copy data from user space to kernel space.
  2209. *
  2210. @@ -348,7 +352,8 @@
  2211. * strlen_user: - Get the size of a string in user space.
  2212. * @str: The string to measure.
  2213. *
  2214. - * Context: User context only. This function may sleep.
  2215. + * Context: User context only. This function may sleep if pagefaults are
  2216. + * enabled.
  2217. *
  2218. * Get the size of a NUL-terminated string in user space.
  2219. *
  2220. diff -Nur linux-4.1.6.orig/arch/s390/kvm/interrupt.c linux-4.1.6/arch/s390/kvm/interrupt.c
  2221. --- linux-4.1.6.orig/arch/s390/kvm/interrupt.c 2015-08-17 05:52:51.000000000 +0200
  2222. +++ linux-4.1.6/arch/s390/kvm/interrupt.c 2015-09-08 23:49:05.250184055 +0200
  2223. @@ -875,13 +875,13 @@
  2224. void kvm_s390_vcpu_wakeup(struct kvm_vcpu *vcpu)
  2225. {
  2226. - if (waitqueue_active(&vcpu->wq)) {
  2227. + if (swaitqueue_active(&vcpu->wq)) {
  2228. /*
  2229. * The vcpu gave up the cpu voluntarily, mark it as a good
  2230. * yield-candidate.
  2231. */
  2232. vcpu->preempted = true;
  2233. - wake_up_interruptible(&vcpu->wq);
  2234. + swait_wake_interruptible(&vcpu->wq);
  2235. vcpu->stat.halt_wakeup++;
  2236. }
  2237. }
  2238. @@ -987,7 +987,7 @@
  2239. spin_lock(&li->lock);
  2240. irq.u.pgm.code = code;
  2241. __inject_prog(vcpu, &irq);
  2242. - BUG_ON(waitqueue_active(li->wq));
  2243. + BUG_ON(swaitqueue_active(li->wq));
  2244. spin_unlock(&li->lock);
  2245. return 0;
  2246. }
  2247. @@ -1006,7 +1006,7 @@
  2248. spin_lock(&li->lock);
  2249. irq.u.pgm = *pgm_info;
  2250. rc = __inject_prog(vcpu, &irq);
  2251. - BUG_ON(waitqueue_active(li->wq));
  2252. + BUG_ON(swaitqueue_active(li->wq));
  2253. spin_unlock(&li->lock);
  2254. return rc;
  2255. }
  2256. diff -Nur linux-4.1.6.orig/arch/s390/mm/fault.c linux-4.1.6/arch/s390/mm/fault.c
  2257. --- linux-4.1.6.orig/arch/s390/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2258. +++ linux-4.1.6/arch/s390/mm/fault.c 2015-09-08 23:49:05.254183611 +0200
  2259. @@ -399,7 +399,7 @@
  2260. * user context.
  2261. */
  2262. fault = VM_FAULT_BADCONTEXT;
  2263. - if (unlikely(!user_space_fault(regs) || in_atomic() || !mm))
  2264. + if (unlikely(!user_space_fault(regs) || faulthandler_disabled() || !mm))
  2265. goto out;
  2266. address = trans_exc_code & __FAIL_ADDR_MASK;
  2267. diff -Nur linux-4.1.6.orig/arch/score/include/asm/uaccess.h linux-4.1.6/arch/score/include/asm/uaccess.h
  2268. --- linux-4.1.6.orig/arch/score/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  2269. +++ linux-4.1.6/arch/score/include/asm/uaccess.h 2015-09-08 23:49:05.254183611 +0200
  2270. @@ -36,7 +36,8 @@
  2271. * @addr: User space pointer to start of block to check
  2272. * @size: Size of block to check
  2273. *
  2274. - * Context: User context only. This function may sleep.
  2275. + * Context: User context only. This function may sleep if pagefaults are
  2276. + * enabled.
  2277. *
  2278. * Checks if a pointer to a block of memory in user space is valid.
  2279. *
  2280. @@ -61,7 +62,8 @@
  2281. * @x: Value to copy to user space.
  2282. * @ptr: Destination address, in user space.
  2283. *
  2284. - * Context: User context only. This function may sleep.
  2285. + * Context: User context only. This function may sleep if pagefaults are
  2286. + * enabled.
  2287. *
  2288. * This macro copies a single simple value from kernel space to user
  2289. * space. It supports simple types like char and int, but not larger
  2290. @@ -79,7 +81,8 @@
  2291. * @x: Variable to store result.
  2292. * @ptr: Source address, in user space.
  2293. *
  2294. - * Context: User context only. This function may sleep.
  2295. + * Context: User context only. This function may sleep if pagefaults are
  2296. + * enabled.
  2297. *
  2298. * This macro copies a single simple variable from user space to kernel
  2299. * space. It supports simple types like char and int, but not larger
  2300. @@ -98,7 +101,8 @@
  2301. * @x: Value to copy to user space.
  2302. * @ptr: Destination address, in user space.
  2303. *
  2304. - * Context: User context only. This function may sleep.
  2305. + * Context: User context only. This function may sleep if pagefaults are
  2306. + * enabled.
  2307. *
  2308. * This macro copies a single simple value from kernel space to user
  2309. * space. It supports simple types like char and int, but not larger
  2310. @@ -119,7 +123,8 @@
  2311. * @x: Variable to store result.
  2312. * @ptr: Source address, in user space.
  2313. *
  2314. - * Context: User context only. This function may sleep.
  2315. + * Context: User context only. This function may sleep if pagefaults are
  2316. + * enabled.
  2317. *
  2318. * This macro copies a single simple variable from user space to kernel
  2319. * space. It supports simple types like char and int, but not larger
  2320. diff -Nur linux-4.1.6.orig/arch/score/mm/fault.c linux-4.1.6/arch/score/mm/fault.c
  2321. --- linux-4.1.6.orig/arch/score/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2322. +++ linux-4.1.6/arch/score/mm/fault.c 2015-09-08 23:49:05.254183611 +0200
  2323. @@ -34,6 +34,7 @@
  2324. #include <linux/string.h>
  2325. #include <linux/types.h>
  2326. #include <linux/ptrace.h>
  2327. +#include <linux/uaccess.h>
  2328. /*
  2329. * This routine handles page faults. It determines the address,
  2330. @@ -73,7 +74,7 @@
  2331. * If we're in an interrupt or have no user
  2332. * context, we must not take the fault..
  2333. */
  2334. - if (in_atomic() || !mm)
  2335. + if (pagefault_disabled() || !mm)
  2336. goto bad_area_nosemaphore;
  2337. if (user_mode(regs))
  2338. diff -Nur linux-4.1.6.orig/arch/sh/kernel/irq.c linux-4.1.6/arch/sh/kernel/irq.c
  2339. --- linux-4.1.6.orig/arch/sh/kernel/irq.c 2015-08-17 05:52:51.000000000 +0200
  2340. +++ linux-4.1.6/arch/sh/kernel/irq.c 2015-09-08 23:49:05.254183611 +0200
  2341. @@ -147,6 +147,7 @@
  2342. hardirq_ctx[cpu] = NULL;
  2343. }
  2344. +#ifndef CONFIG_PREEMPT_RT_FULL
  2345. void do_softirq_own_stack(void)
  2346. {
  2347. struct thread_info *curctx;
  2348. @@ -174,6 +175,7 @@
  2349. "r5", "r6", "r7", "r8", "r9", "r15", "t", "pr"
  2350. );
  2351. }
  2352. +#endif
  2353. #else
  2354. static inline void handle_one_irq(unsigned int irq)
  2355. {
  2356. diff -Nur linux-4.1.6.orig/arch/sh/mm/fault.c linux-4.1.6/arch/sh/mm/fault.c
  2357. --- linux-4.1.6.orig/arch/sh/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2358. +++ linux-4.1.6/arch/sh/mm/fault.c 2015-09-08 23:49:05.258183169 +0200
  2359. @@ -17,6 +17,7 @@
  2360. #include <linux/kprobes.h>
  2361. #include <linux/perf_event.h>
  2362. #include <linux/kdebug.h>
  2363. +#include <linux/uaccess.h>
  2364. #include <asm/io_trapped.h>
  2365. #include <asm/mmu_context.h>
  2366. #include <asm/tlbflush.h>
  2367. @@ -438,9 +439,9 @@
  2368. /*
  2369. * If we're in an interrupt, have no user context or are running
  2370. - * in an atomic region then we must not take the fault:
  2371. + * with pagefaults disabled then we must not take the fault:
  2372. */
  2373. - if (unlikely(in_atomic() || !mm)) {
  2374. + if (unlikely(faulthandler_disabled() || !mm)) {
  2375. bad_area_nosemaphore(regs, error_code, address);
  2376. return;
  2377. }
  2378. diff -Nur linux-4.1.6.orig/arch/sparc/Kconfig linux-4.1.6/arch/sparc/Kconfig
  2379. --- linux-4.1.6.orig/arch/sparc/Kconfig 2015-08-17 05:52:51.000000000 +0200
  2380. +++ linux-4.1.6/arch/sparc/Kconfig 2015-09-08 23:49:05.258183169 +0200
  2381. @@ -189,12 +189,10 @@
  2382. source kernel/Kconfig.hz
  2383. config RWSEM_GENERIC_SPINLOCK
  2384. - bool
  2385. - default y if SPARC32
  2386. + def_bool PREEMPT_RT_FULL
  2387. config RWSEM_XCHGADD_ALGORITHM
  2388. - bool
  2389. - default y if SPARC64
  2390. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  2391. config GENERIC_HWEIGHT
  2392. bool
  2393. diff -Nur linux-4.1.6.orig/arch/sparc/kernel/irq_64.c linux-4.1.6/arch/sparc/kernel/irq_64.c
  2394. --- linux-4.1.6.orig/arch/sparc/kernel/irq_64.c 2015-08-17 05:52:51.000000000 +0200
  2395. +++ linux-4.1.6/arch/sparc/kernel/irq_64.c 2015-09-08 23:49:05.258183169 +0200
  2396. @@ -849,6 +849,7 @@
  2397. set_irq_regs(old_regs);
  2398. }
  2399. +#ifndef CONFIG_PREEMPT_RT_FULL
  2400. void do_softirq_own_stack(void)
  2401. {
  2402. void *orig_sp, *sp = softirq_stack[smp_processor_id()];
  2403. @@ -863,6 +864,7 @@
  2404. __asm__ __volatile__("mov %0, %%sp"
  2405. : : "r" (orig_sp));
  2406. }
  2407. +#endif
  2408. #ifdef CONFIG_HOTPLUG_CPU
  2409. void fixup_irqs(void)
  2410. diff -Nur linux-4.1.6.orig/arch/sparc/mm/fault_32.c linux-4.1.6/arch/sparc/mm/fault_32.c
  2411. --- linux-4.1.6.orig/arch/sparc/mm/fault_32.c 2015-08-17 05:52:51.000000000 +0200
  2412. +++ linux-4.1.6/arch/sparc/mm/fault_32.c 2015-09-08 23:49:05.258183169 +0200
  2413. @@ -21,6 +21,7 @@
  2414. #include <linux/perf_event.h>
  2415. #include <linux/interrupt.h>
  2416. #include <linux/kdebug.h>
  2417. +#include <linux/uaccess.h>
  2418. #include <asm/page.h>
  2419. #include <asm/pgtable.h>
  2420. @@ -29,7 +30,6 @@
  2421. #include <asm/setup.h>
  2422. #include <asm/smp.h>
  2423. #include <asm/traps.h>
  2424. -#include <asm/uaccess.h>
  2425. #include "mm_32.h"
  2426. @@ -196,7 +196,7 @@
  2427. * If we're in an interrupt or have no user
  2428. * context, we must not take the fault..
  2429. */
  2430. - if (in_atomic() || !mm)
  2431. + if (pagefault_disabled() || !mm)
  2432. goto no_context;
  2433. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  2434. diff -Nur linux-4.1.6.orig/arch/sparc/mm/fault_64.c linux-4.1.6/arch/sparc/mm/fault_64.c
  2435. --- linux-4.1.6.orig/arch/sparc/mm/fault_64.c 2015-08-17 05:52:51.000000000 +0200
  2436. +++ linux-4.1.6/arch/sparc/mm/fault_64.c 2015-09-08 23:49:05.262182726 +0200
  2437. @@ -22,12 +22,12 @@
  2438. #include <linux/kdebug.h>
  2439. #include <linux/percpu.h>
  2440. #include <linux/context_tracking.h>
  2441. +#include <linux/uaccess.h>
  2442. #include <asm/page.h>
  2443. #include <asm/pgtable.h>
  2444. #include <asm/openprom.h>
  2445. #include <asm/oplib.h>
  2446. -#include <asm/uaccess.h>
  2447. #include <asm/asi.h>
  2448. #include <asm/lsu.h>
  2449. #include <asm/sections.h>
  2450. @@ -330,7 +330,7 @@
  2451. * If we're in an interrupt or have no user
  2452. * context, we must not take the fault..
  2453. */
  2454. - if (in_atomic() || !mm)
  2455. + if (faulthandler_disabled() || !mm)
  2456. goto intr_or_no_mm;
  2457. perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address);
  2458. diff -Nur linux-4.1.6.orig/arch/sparc/mm/highmem.c linux-4.1.6/arch/sparc/mm/highmem.c
  2459. --- linux-4.1.6.orig/arch/sparc/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  2460. +++ linux-4.1.6/arch/sparc/mm/highmem.c 2015-09-08 23:49:05.262182726 +0200
  2461. @@ -53,7 +53,7 @@
  2462. unsigned long vaddr;
  2463. long idx, type;
  2464. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2465. + preempt_disable();
  2466. pagefault_disable();
  2467. if (!PageHighMem(page))
  2468. return page_address(page);
  2469. @@ -91,6 +91,7 @@
  2470. if (vaddr < FIXADDR_START) { // FIXME
  2471. pagefault_enable();
  2472. + preempt_enable();
  2473. return;
  2474. }
  2475. @@ -126,5 +127,6 @@
  2476. kmap_atomic_idx_pop();
  2477. pagefault_enable();
  2478. + preempt_enable();
  2479. }
  2480. EXPORT_SYMBOL(__kunmap_atomic);
  2481. diff -Nur linux-4.1.6.orig/arch/sparc/mm/init_64.c linux-4.1.6/arch/sparc/mm/init_64.c
  2482. --- linux-4.1.6.orig/arch/sparc/mm/init_64.c 2015-08-17 05:52:51.000000000 +0200
  2483. +++ linux-4.1.6/arch/sparc/mm/init_64.c 2015-09-08 23:49:05.262182726 +0200
  2484. @@ -2738,7 +2738,7 @@
  2485. struct mm_struct *mm = current->mm;
  2486. struct tsb_config *tp;
  2487. - if (in_atomic() || !mm) {
  2488. + if (faulthandler_disabled() || !mm) {
  2489. const struct exception_table_entry *entry;
  2490. entry = search_exception_tables(regs->tpc);
  2491. diff -Nur linux-4.1.6.orig/arch/tile/include/asm/uaccess.h linux-4.1.6/arch/tile/include/asm/uaccess.h
  2492. --- linux-4.1.6.orig/arch/tile/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  2493. +++ linux-4.1.6/arch/tile/include/asm/uaccess.h 2015-09-08 23:49:05.266182281 +0200
  2494. @@ -78,7 +78,8 @@
  2495. * @addr: User space pointer to start of block to check
  2496. * @size: Size of block to check
  2497. *
  2498. - * Context: User context only. This function may sleep.
  2499. + * Context: User context only. This function may sleep if pagefaults are
  2500. + * enabled.
  2501. *
  2502. * Checks if a pointer to a block of memory in user space is valid.
  2503. *
  2504. @@ -192,7 +193,8 @@
  2505. * @x: Variable to store result.
  2506. * @ptr: Source address, in user space.
  2507. *
  2508. - * Context: User context only. This function may sleep.
  2509. + * Context: User context only. This function may sleep if pagefaults are
  2510. + * enabled.
  2511. *
  2512. * This macro copies a single simple variable from user space to kernel
  2513. * space. It supports simple types like char and int, but not larger
  2514. @@ -274,7 +276,8 @@
  2515. * @x: Value to copy to user space.
  2516. * @ptr: Destination address, in user space.
  2517. *
  2518. - * Context: User context only. This function may sleep.
  2519. + * Context: User context only. This function may sleep if pagefaults are
  2520. + * enabled.
  2521. *
  2522. * This macro copies a single simple value from kernel space to user
  2523. * space. It supports simple types like char and int, but not larger
  2524. @@ -330,7 +333,8 @@
  2525. * @from: Source address, in kernel space.
  2526. * @n: Number of bytes to copy.
  2527. *
  2528. - * Context: User context only. This function may sleep.
  2529. + * Context: User context only. This function may sleep if pagefaults are
  2530. + * enabled.
  2531. *
  2532. * Copy data from kernel space to user space. Caller must check
  2533. * the specified block with access_ok() before calling this function.
  2534. @@ -366,7 +370,8 @@
  2535. * @from: Source address, in user space.
  2536. * @n: Number of bytes to copy.
  2537. *
  2538. - * Context: User context only. This function may sleep.
  2539. + * Context: User context only. This function may sleep if pagefaults are
  2540. + * enabled.
  2541. *
  2542. * Copy data from user space to kernel space. Caller must check
  2543. * the specified block with access_ok() before calling this function.
  2544. @@ -437,7 +442,8 @@
  2545. * @from: Source address, in user space.
  2546. * @n: Number of bytes to copy.
  2547. *
  2548. - * Context: User context only. This function may sleep.
  2549. + * Context: User context only. This function may sleep if pagefaults are
  2550. + * enabled.
  2551. *
  2552. * Copy data from user space to user space. Caller must check
  2553. * the specified blocks with access_ok() before calling this function.
  2554. diff -Nur linux-4.1.6.orig/arch/tile/mm/fault.c linux-4.1.6/arch/tile/mm/fault.c
  2555. --- linux-4.1.6.orig/arch/tile/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2556. +++ linux-4.1.6/arch/tile/mm/fault.c 2015-09-08 23:49:05.266182281 +0200
  2557. @@ -354,9 +354,9 @@
  2558. /*
  2559. * If we're in an interrupt, have no user context or are running in an
  2560. - * atomic region then we must not take the fault.
  2561. + * region with pagefaults disabled then we must not take the fault.
  2562. */
  2563. - if (in_atomic() || !mm) {
  2564. + if (pagefault_disabled() || !mm) {
  2565. vma = NULL; /* happy compiler */
  2566. goto bad_area_nosemaphore;
  2567. }
  2568. diff -Nur linux-4.1.6.orig/arch/tile/mm/highmem.c linux-4.1.6/arch/tile/mm/highmem.c
  2569. --- linux-4.1.6.orig/arch/tile/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  2570. +++ linux-4.1.6/arch/tile/mm/highmem.c 2015-09-08 23:49:05.266182281 +0200
  2571. @@ -201,7 +201,7 @@
  2572. int idx, type;
  2573. pte_t *pte;
  2574. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  2575. + preempt_disable();
  2576. pagefault_disable();
  2577. /* Avoid icache flushes by disallowing atomic executable mappings. */
  2578. @@ -259,6 +259,7 @@
  2579. }
  2580. pagefault_enable();
  2581. + preempt_enable();
  2582. }
  2583. EXPORT_SYMBOL(__kunmap_atomic);
  2584. diff -Nur linux-4.1.6.orig/arch/um/kernel/trap.c linux-4.1.6/arch/um/kernel/trap.c
  2585. --- linux-4.1.6.orig/arch/um/kernel/trap.c 2015-08-17 05:52:51.000000000 +0200
  2586. +++ linux-4.1.6/arch/um/kernel/trap.c 2015-09-08 23:49:05.266182281 +0200
  2587. @@ -35,10 +35,10 @@
  2588. *code_out = SEGV_MAPERR;
  2589. /*
  2590. - * If the fault was during atomic operation, don't take the fault, just
  2591. + * If the fault was with pagefaults disabled, don't take the fault, just
  2592. * fail.
  2593. */
  2594. - if (in_atomic())
  2595. + if (faulthandler_disabled())
  2596. goto out_nosemaphore;
  2597. if (is_user)
  2598. diff -Nur linux-4.1.6.orig/arch/unicore32/mm/fault.c linux-4.1.6/arch/unicore32/mm/fault.c
  2599. --- linux-4.1.6.orig/arch/unicore32/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  2600. +++ linux-4.1.6/arch/unicore32/mm/fault.c 2015-09-08 23:49:05.266182281 +0200
  2601. @@ -218,7 +218,7 @@
  2602. * If we're in an interrupt or have no user
  2603. * context, we must not take the fault..
  2604. */
  2605. - if (in_atomic() || !mm)
  2606. + if (faulthandler_disabled() || !mm)
  2607. goto no_context;
  2608. if (user_mode(regs))
  2609. diff -Nur linux-4.1.6.orig/arch/x86/crypto/aesni-intel_glue.c linux-4.1.6/arch/x86/crypto/aesni-intel_glue.c
  2610. --- linux-4.1.6.orig/arch/x86/crypto/aesni-intel_glue.c 2015-08-17 05:52:51.000000000 +0200
  2611. +++ linux-4.1.6/arch/x86/crypto/aesni-intel_glue.c 2015-09-08 23:49:05.270181837 +0200
  2612. @@ -382,14 +382,14 @@
  2613. err = blkcipher_walk_virt(desc, &walk);
  2614. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2615. - kernel_fpu_begin();
  2616. while ((nbytes = walk.nbytes)) {
  2617. + kernel_fpu_begin();
  2618. aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2619. - nbytes & AES_BLOCK_MASK);
  2620. + nbytes & AES_BLOCK_MASK);
  2621. + kernel_fpu_end();
  2622. nbytes &= AES_BLOCK_SIZE - 1;
  2623. err = blkcipher_walk_done(desc, &walk, nbytes);
  2624. }
  2625. - kernel_fpu_end();
  2626. return err;
  2627. }
  2628. @@ -406,14 +406,14 @@
  2629. err = blkcipher_walk_virt(desc, &walk);
  2630. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2631. - kernel_fpu_begin();
  2632. while ((nbytes = walk.nbytes)) {
  2633. + kernel_fpu_begin();
  2634. aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2635. nbytes & AES_BLOCK_MASK);
  2636. + kernel_fpu_end();
  2637. nbytes &= AES_BLOCK_SIZE - 1;
  2638. err = blkcipher_walk_done(desc, &walk, nbytes);
  2639. }
  2640. - kernel_fpu_end();
  2641. return err;
  2642. }
  2643. @@ -430,14 +430,14 @@
  2644. err = blkcipher_walk_virt(desc, &walk);
  2645. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2646. - kernel_fpu_begin();
  2647. while ((nbytes = walk.nbytes)) {
  2648. + kernel_fpu_begin();
  2649. aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2650. nbytes & AES_BLOCK_MASK, walk.iv);
  2651. + kernel_fpu_end();
  2652. nbytes &= AES_BLOCK_SIZE - 1;
  2653. err = blkcipher_walk_done(desc, &walk, nbytes);
  2654. }
  2655. - kernel_fpu_end();
  2656. return err;
  2657. }
  2658. @@ -454,14 +454,14 @@
  2659. err = blkcipher_walk_virt(desc, &walk);
  2660. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2661. - kernel_fpu_begin();
  2662. while ((nbytes = walk.nbytes)) {
  2663. + kernel_fpu_begin();
  2664. aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2665. nbytes & AES_BLOCK_MASK, walk.iv);
  2666. + kernel_fpu_end();
  2667. nbytes &= AES_BLOCK_SIZE - 1;
  2668. err = blkcipher_walk_done(desc, &walk, nbytes);
  2669. }
  2670. - kernel_fpu_end();
  2671. return err;
  2672. }
  2673. @@ -513,18 +513,20 @@
  2674. err = blkcipher_walk_virt_block(desc, &walk, AES_BLOCK_SIZE);
  2675. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2676. - kernel_fpu_begin();
  2677. while ((nbytes = walk.nbytes) >= AES_BLOCK_SIZE) {
  2678. + kernel_fpu_begin();
  2679. aesni_ctr_enc_tfm(ctx, walk.dst.virt.addr, walk.src.virt.addr,
  2680. nbytes & AES_BLOCK_MASK, walk.iv);
  2681. + kernel_fpu_end();
  2682. nbytes &= AES_BLOCK_SIZE - 1;
  2683. err = blkcipher_walk_done(desc, &walk, nbytes);
  2684. }
  2685. if (walk.nbytes) {
  2686. + kernel_fpu_begin();
  2687. ctr_crypt_final(ctx, &walk);
  2688. + kernel_fpu_end();
  2689. err = blkcipher_walk_done(desc, &walk, 0);
  2690. }
  2691. - kernel_fpu_end();
  2692. return err;
  2693. }
  2694. diff -Nur linux-4.1.6.orig/arch/x86/crypto/cast5_avx_glue.c linux-4.1.6/arch/x86/crypto/cast5_avx_glue.c
  2695. --- linux-4.1.6.orig/arch/x86/crypto/cast5_avx_glue.c 2015-08-17 05:52:51.000000000 +0200
  2696. +++ linux-4.1.6/arch/x86/crypto/cast5_avx_glue.c 2015-09-08 23:49:05.270181837 +0200
  2697. @@ -60,7 +60,7 @@
  2698. static int ecb_crypt(struct blkcipher_desc *desc, struct blkcipher_walk *walk,
  2699. bool enc)
  2700. {
  2701. - bool fpu_enabled = false;
  2702. + bool fpu_enabled;
  2703. struct cast5_ctx *ctx = crypto_blkcipher_ctx(desc->tfm);
  2704. const unsigned int bsize = CAST5_BLOCK_SIZE;
  2705. unsigned int nbytes;
  2706. @@ -76,7 +76,7 @@
  2707. u8 *wsrc = walk->src.virt.addr;
  2708. u8 *wdst = walk->dst.virt.addr;
  2709. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2710. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2711. /* Process multi-block batch */
  2712. if (nbytes >= bsize * CAST5_PARALLEL_BLOCKS) {
  2713. @@ -104,10 +104,9 @@
  2714. } while (nbytes >= bsize);
  2715. done:
  2716. + cast5_fpu_end(fpu_enabled);
  2717. err = blkcipher_walk_done(desc, walk, nbytes);
  2718. }
  2719. -
  2720. - cast5_fpu_end(fpu_enabled);
  2721. return err;
  2722. }
  2723. @@ -228,7 +227,7 @@
  2724. static int cbc_decrypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  2725. struct scatterlist *src, unsigned int nbytes)
  2726. {
  2727. - bool fpu_enabled = false;
  2728. + bool fpu_enabled;
  2729. struct blkcipher_walk walk;
  2730. int err;
  2731. @@ -237,12 +236,11 @@
  2732. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2733. while ((nbytes = walk.nbytes)) {
  2734. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2735. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2736. nbytes = __cbc_decrypt(desc, &walk);
  2737. + cast5_fpu_end(fpu_enabled);
  2738. err = blkcipher_walk_done(desc, &walk, nbytes);
  2739. }
  2740. -
  2741. - cast5_fpu_end(fpu_enabled);
  2742. return err;
  2743. }
  2744. @@ -312,7 +310,7 @@
  2745. static int ctr_crypt(struct blkcipher_desc *desc, struct scatterlist *dst,
  2746. struct scatterlist *src, unsigned int nbytes)
  2747. {
  2748. - bool fpu_enabled = false;
  2749. + bool fpu_enabled;
  2750. struct blkcipher_walk walk;
  2751. int err;
  2752. @@ -321,13 +319,12 @@
  2753. desc->flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  2754. while ((nbytes = walk.nbytes) >= CAST5_BLOCK_SIZE) {
  2755. - fpu_enabled = cast5_fpu_begin(fpu_enabled, nbytes);
  2756. + fpu_enabled = cast5_fpu_begin(false, nbytes);
  2757. nbytes = __ctr_crypt(desc, &walk);
  2758. + cast5_fpu_end(fpu_enabled);
  2759. err = blkcipher_walk_done(desc, &walk, nbytes);
  2760. }
  2761. - cast5_fpu_end(fpu_enabled);
  2762. -
  2763. if (walk.nbytes) {
  2764. ctr_crypt_final(desc, &walk);
  2765. err = blkcipher_walk_done(desc, &walk, 0);
  2766. diff -Nur linux-4.1.6.orig/arch/x86/crypto/glue_helper.c linux-4.1.6/arch/x86/crypto/glue_helper.c
  2767. --- linux-4.1.6.orig/arch/x86/crypto/glue_helper.c 2015-08-17 05:52:51.000000000 +0200
  2768. +++ linux-4.1.6/arch/x86/crypto/glue_helper.c 2015-09-08 23:49:05.270181837 +0200
  2769. @@ -39,7 +39,7 @@
  2770. void *ctx = crypto_blkcipher_ctx(desc->tfm);
  2771. const unsigned int bsize = 128 / 8;
  2772. unsigned int nbytes, i, func_bytes;
  2773. - bool fpu_enabled = false;
  2774. + bool fpu_enabled;
  2775. int err;
  2776. err = blkcipher_walk_virt(desc, walk);
  2777. @@ -49,7 +49,7 @@
  2778. u8 *wdst = walk->dst.virt.addr;
  2779. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2780. - desc, fpu_enabled, nbytes);
  2781. + desc, false, nbytes);
  2782. for (i = 0; i < gctx->num_funcs; i++) {
  2783. func_bytes = bsize * gctx->funcs[i].num_blocks;
  2784. @@ -71,10 +71,10 @@
  2785. }
  2786. done:
  2787. + glue_fpu_end(fpu_enabled);
  2788. err = blkcipher_walk_done(desc, walk, nbytes);
  2789. }
  2790. - glue_fpu_end(fpu_enabled);
  2791. return err;
  2792. }
  2793. @@ -194,7 +194,7 @@
  2794. struct scatterlist *src, unsigned int nbytes)
  2795. {
  2796. const unsigned int bsize = 128 / 8;
  2797. - bool fpu_enabled = false;
  2798. + bool fpu_enabled;
  2799. struct blkcipher_walk walk;
  2800. int err;
  2801. @@ -203,12 +203,12 @@
  2802. while ((nbytes = walk.nbytes)) {
  2803. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2804. - desc, fpu_enabled, nbytes);
  2805. + desc, false, nbytes);
  2806. nbytes = __glue_cbc_decrypt_128bit(gctx, desc, &walk);
  2807. + glue_fpu_end(fpu_enabled);
  2808. err = blkcipher_walk_done(desc, &walk, nbytes);
  2809. }
  2810. - glue_fpu_end(fpu_enabled);
  2811. return err;
  2812. }
  2813. EXPORT_SYMBOL_GPL(glue_cbc_decrypt_128bit);
  2814. @@ -277,7 +277,7 @@
  2815. struct scatterlist *src, unsigned int nbytes)
  2816. {
  2817. const unsigned int bsize = 128 / 8;
  2818. - bool fpu_enabled = false;
  2819. + bool fpu_enabled;
  2820. struct blkcipher_walk walk;
  2821. int err;
  2822. @@ -286,13 +286,12 @@
  2823. while ((nbytes = walk.nbytes) >= bsize) {
  2824. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2825. - desc, fpu_enabled, nbytes);
  2826. + desc, false, nbytes);
  2827. nbytes = __glue_ctr_crypt_128bit(gctx, desc, &walk);
  2828. + glue_fpu_end(fpu_enabled);
  2829. err = blkcipher_walk_done(desc, &walk, nbytes);
  2830. }
  2831. - glue_fpu_end(fpu_enabled);
  2832. -
  2833. if (walk.nbytes) {
  2834. glue_ctr_crypt_final_128bit(
  2835. gctx->funcs[gctx->num_funcs - 1].fn_u.ctr, desc, &walk);
  2836. @@ -347,7 +346,7 @@
  2837. void *tweak_ctx, void *crypt_ctx)
  2838. {
  2839. const unsigned int bsize = 128 / 8;
  2840. - bool fpu_enabled = false;
  2841. + bool fpu_enabled;
  2842. struct blkcipher_walk walk;
  2843. int err;
  2844. @@ -360,21 +359,21 @@
  2845. /* set minimum length to bsize, for tweak_fn */
  2846. fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2847. - desc, fpu_enabled,
  2848. + desc, false,
  2849. nbytes < bsize ? bsize : nbytes);
  2850. -
  2851. /* calculate first value of T */
  2852. tweak_fn(tweak_ctx, walk.iv, walk.iv);
  2853. + glue_fpu_end(fpu_enabled);
  2854. while (nbytes) {
  2855. + fpu_enabled = glue_fpu_begin(bsize, gctx->fpu_blocks_limit,
  2856. + desc, false, nbytes);
  2857. nbytes = __glue_xts_crypt_128bit(gctx, crypt_ctx, desc, &walk);
  2858. + glue_fpu_end(fpu_enabled);
  2859. err = blkcipher_walk_done(desc, &walk, nbytes);
  2860. nbytes = walk.nbytes;
  2861. }
  2862. -
  2863. - glue_fpu_end(fpu_enabled);
  2864. -
  2865. return err;
  2866. }
  2867. EXPORT_SYMBOL_GPL(glue_xts_crypt_128bit);
  2868. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/preempt.h linux-4.1.6/arch/x86/include/asm/preempt.h
  2869. --- linux-4.1.6.orig/arch/x86/include/asm/preempt.h 2015-08-17 05:52:51.000000000 +0200
  2870. +++ linux-4.1.6/arch/x86/include/asm/preempt.h 2015-09-08 23:49:05.270181837 +0200
  2871. @@ -82,17 +82,33 @@
  2872. * a decrement which hits zero means we have no preempt_count and should
  2873. * reschedule.
  2874. */
  2875. -static __always_inline bool __preempt_count_dec_and_test(void)
  2876. +static __always_inline bool ____preempt_count_dec_and_test(void)
  2877. {
  2878. GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
  2879. }
  2880. +static __always_inline bool __preempt_count_dec_and_test(void)
  2881. +{
  2882. + if (____preempt_count_dec_and_test())
  2883. + return true;
  2884. +#ifdef CONFIG_PREEMPT_LAZY
  2885. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  2886. +#else
  2887. + return false;
  2888. +#endif
  2889. +}
  2890. +
  2891. /*
  2892. * Returns true when we need to resched and can (barring IRQ state).
  2893. */
  2894. static __always_inline bool should_resched(void)
  2895. {
  2896. +#ifdef CONFIG_PREEMPT_LAZY
  2897. + return unlikely(!raw_cpu_read_4(__preempt_count) || \
  2898. + test_thread_flag(TIF_NEED_RESCHED_LAZY));
  2899. +#else
  2900. return unlikely(!raw_cpu_read_4(__preempt_count));
  2901. +#endif
  2902. }
  2903. #ifdef CONFIG_PREEMPT
  2904. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/signal.h linux-4.1.6/arch/x86/include/asm/signal.h
  2905. --- linux-4.1.6.orig/arch/x86/include/asm/signal.h 2015-08-17 05:52:51.000000000 +0200
  2906. +++ linux-4.1.6/arch/x86/include/asm/signal.h 2015-09-08 23:49:05.270181837 +0200
  2907. @@ -23,6 +23,19 @@
  2908. unsigned long sig[_NSIG_WORDS];
  2909. } sigset_t;
  2910. +/*
  2911. + * Because some traps use the IST stack, we must keep preemption
  2912. + * disabled while calling do_trap(), but do_trap() may call
  2913. + * force_sig_info() which will grab the signal spin_locks for the
  2914. + * task, which in PREEMPT_RT_FULL are mutexes. By defining
  2915. + * ARCH_RT_DELAYS_SIGNAL_SEND the force_sig_info() will set
  2916. + * TIF_NOTIFY_RESUME and set up the signal to be sent on exit of the
  2917. + * trap.
  2918. + */
  2919. +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_X86_64)
  2920. +#define ARCH_RT_DELAYS_SIGNAL_SEND
  2921. +#endif
  2922. +
  2923. #ifndef CONFIG_COMPAT
  2924. typedef sigset_t compat_sigset_t;
  2925. #endif
  2926. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/stackprotector.h linux-4.1.6/arch/x86/include/asm/stackprotector.h
  2927. --- linux-4.1.6.orig/arch/x86/include/asm/stackprotector.h 2015-08-17 05:52:51.000000000 +0200
  2928. +++ linux-4.1.6/arch/x86/include/asm/stackprotector.h 2015-09-08 23:49:05.298178732 +0200
  2929. @@ -57,7 +57,7 @@
  2930. */
  2931. static __always_inline void boot_init_stack_canary(void)
  2932. {
  2933. - u64 canary;
  2934. + u64 uninitialized_var(canary);
  2935. u64 tsc;
  2936. #ifdef CONFIG_X86_64
  2937. @@ -68,8 +68,16 @@
  2938. * of randomness. The TSC only matters for very early init,
  2939. * there it already has some randomness on most systems. Later
  2940. * on during the bootup the random pool has true entropy too.
  2941. + *
  2942. + * For preempt-rt we need to weaken the randomness a bit, as
  2943. + * we can't call into the random generator from atomic context
  2944. + * due to locking constraints. We just leave canary
  2945. + * uninitialized and use the TSC based randomness on top of
  2946. + * it.
  2947. */
  2948. +#ifndef CONFIG_PREEMPT_RT_FULL
  2949. get_random_bytes(&canary, sizeof(canary));
  2950. +#endif
  2951. tsc = __native_read_tsc();
  2952. canary += tsc + (tsc << 32UL);
  2953. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/thread_info.h linux-4.1.6/arch/x86/include/asm/thread_info.h
  2954. --- linux-4.1.6.orig/arch/x86/include/asm/thread_info.h 2015-08-17 05:52:51.000000000 +0200
  2955. +++ linux-4.1.6/arch/x86/include/asm/thread_info.h 2015-09-08 23:49:05.514154783 +0200
  2956. @@ -55,6 +55,8 @@
  2957. __u32 status; /* thread synchronous flags */
  2958. __u32 cpu; /* current CPU */
  2959. int saved_preempt_count;
  2960. + int preempt_lazy_count; /* 0 => lazy preemptable
  2961. + <0 => BUG */
  2962. mm_segment_t addr_limit;
  2963. void __user *sysenter_return;
  2964. unsigned int sig_on_uaccess_error:1;
  2965. @@ -95,6 +97,7 @@
  2966. #define TIF_SYSCALL_EMU 6 /* syscall emulation active */
  2967. #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
  2968. #define TIF_SECCOMP 8 /* secure computing */
  2969. +#define TIF_NEED_RESCHED_LAZY 9 /* lazy rescheduling necessary */
  2970. #define TIF_USER_RETURN_NOTIFY 11 /* notify kernel of userspace return */
  2971. #define TIF_UPROBE 12 /* breakpointed or singlestepping */
  2972. #define TIF_NOTSC 16 /* TSC is not accessible in userland */
  2973. @@ -119,6 +122,7 @@
  2974. #define _TIF_SYSCALL_EMU (1 << TIF_SYSCALL_EMU)
  2975. #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
  2976. #define _TIF_SECCOMP (1 << TIF_SECCOMP)
  2977. +#define _TIF_NEED_RESCHED_LAZY (1 << TIF_NEED_RESCHED_LAZY)
  2978. #define _TIF_USER_RETURN_NOTIFY (1 << TIF_USER_RETURN_NOTIFY)
  2979. #define _TIF_UPROBE (1 << TIF_UPROBE)
  2980. #define _TIF_NOTSC (1 << TIF_NOTSC)
  2981. @@ -168,6 +172,8 @@
  2982. #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
  2983. #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
  2984. +#define _TIF_NEED_RESCHED_MASK (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY)
  2985. +
  2986. #define STACK_WARN (THREAD_SIZE/8)
  2987. /*
  2988. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/uaccess_32.h linux-4.1.6/arch/x86/include/asm/uaccess_32.h
  2989. --- linux-4.1.6.orig/arch/x86/include/asm/uaccess_32.h 2015-08-17 05:52:51.000000000 +0200
  2990. +++ linux-4.1.6/arch/x86/include/asm/uaccess_32.h 2015-09-08 23:49:05.514154783 +0200
  2991. @@ -70,7 +70,8 @@
  2992. * @from: Source address, in kernel space.
  2993. * @n: Number of bytes to copy.
  2994. *
  2995. - * Context: User context only. This function may sleep.
  2996. + * Context: User context only. This function may sleep if pagefaults are
  2997. + * enabled.
  2998. *
  2999. * Copy data from kernel space to user space. Caller must check
  3000. * the specified block with access_ok() before calling this function.
  3001. @@ -117,7 +118,8 @@
  3002. * @from: Source address, in user space.
  3003. * @n: Number of bytes to copy.
  3004. *
  3005. - * Context: User context only. This function may sleep.
  3006. + * Context: User context only. This function may sleep if pagefaults are
  3007. + * enabled.
  3008. *
  3009. * Copy data from user space to kernel space. Caller must check
  3010. * the specified block with access_ok() before calling this function.
  3011. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/uaccess.h linux-4.1.6/arch/x86/include/asm/uaccess.h
  3012. --- linux-4.1.6.orig/arch/x86/include/asm/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  3013. +++ linux-4.1.6/arch/x86/include/asm/uaccess.h 2015-09-08 23:49:05.514154783 +0200
  3014. @@ -74,7 +74,8 @@
  3015. * @addr: User space pointer to start of block to check
  3016. * @size: Size of block to check
  3017. *
  3018. - * Context: User context only. This function may sleep.
  3019. + * Context: User context only. This function may sleep if pagefaults are
  3020. + * enabled.
  3021. *
  3022. * Checks if a pointer to a block of memory in user space is valid.
  3023. *
  3024. @@ -145,7 +146,8 @@
  3025. * @x: Variable to store result.
  3026. * @ptr: Source address, in user space.
  3027. *
  3028. - * Context: User context only. This function may sleep.
  3029. + * Context: User context only. This function may sleep if pagefaults are
  3030. + * enabled.
  3031. *
  3032. * This macro copies a single simple variable from user space to kernel
  3033. * space. It supports simple types like char and int, but not larger
  3034. @@ -240,7 +242,8 @@
  3035. * @x: Value to copy to user space.
  3036. * @ptr: Destination address, in user space.
  3037. *
  3038. - * Context: User context only. This function may sleep.
  3039. + * Context: User context only. This function may sleep if pagefaults are
  3040. + * enabled.
  3041. *
  3042. * This macro copies a single simple value from kernel space to user
  3043. * space. It supports simple types like char and int, but not larger
  3044. @@ -455,7 +458,8 @@
  3045. * @x: Variable to store result.
  3046. * @ptr: Source address, in user space.
  3047. *
  3048. - * Context: User context only. This function may sleep.
  3049. + * Context: User context only. This function may sleep if pagefaults are
  3050. + * enabled.
  3051. *
  3052. * This macro copies a single simple variable from user space to kernel
  3053. * space. It supports simple types like char and int, but not larger
  3054. @@ -479,7 +483,8 @@
  3055. * @x: Value to copy to user space.
  3056. * @ptr: Destination address, in user space.
  3057. *
  3058. - * Context: User context only. This function may sleep.
  3059. + * Context: User context only. This function may sleep if pagefaults are
  3060. + * enabled.
  3061. *
  3062. * This macro copies a single simple value from kernel space to user
  3063. * space. It supports simple types like char and int, but not larger
  3064. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/uv/uv_bau.h linux-4.1.6/arch/x86/include/asm/uv/uv_bau.h
  3065. --- linux-4.1.6.orig/arch/x86/include/asm/uv/uv_bau.h 2015-08-17 05:52:51.000000000 +0200
  3066. +++ linux-4.1.6/arch/x86/include/asm/uv/uv_bau.h 2015-09-08 23:49:05.514154783 +0200
  3067. @@ -615,9 +615,9 @@
  3068. cycles_t send_message;
  3069. cycles_t period_end;
  3070. cycles_t period_time;
  3071. - spinlock_t uvhub_lock;
  3072. - spinlock_t queue_lock;
  3073. - spinlock_t disable_lock;
  3074. + raw_spinlock_t uvhub_lock;
  3075. + raw_spinlock_t queue_lock;
  3076. + raw_spinlock_t disable_lock;
  3077. /* tunables */
  3078. int max_concurr;
  3079. int max_concurr_const;
  3080. @@ -776,15 +776,15 @@
  3081. * to be lowered below the current 'v'. atomic_add_unless can only stop
  3082. * on equal.
  3083. */
  3084. -static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
  3085. +static inline int atomic_inc_unless_ge(raw_spinlock_t *lock, atomic_t *v, int u)
  3086. {
  3087. - spin_lock(lock);
  3088. + raw_spin_lock(lock);
  3089. if (atomic_read(v) >= u) {
  3090. - spin_unlock(lock);
  3091. + raw_spin_unlock(lock);
  3092. return 0;
  3093. }
  3094. atomic_inc(v);
  3095. - spin_unlock(lock);
  3096. + raw_spin_unlock(lock);
  3097. return 1;
  3098. }
  3099. diff -Nur linux-4.1.6.orig/arch/x86/include/asm/uv/uv_hub.h linux-4.1.6/arch/x86/include/asm/uv/uv_hub.h
  3100. --- linux-4.1.6.orig/arch/x86/include/asm/uv/uv_hub.h 2015-08-17 05:52:51.000000000 +0200
  3101. +++ linux-4.1.6/arch/x86/include/asm/uv/uv_hub.h 2015-09-08 23:49:05.518154339 +0200
  3102. @@ -492,7 +492,7 @@
  3103. unsigned short nr_online_cpus;
  3104. unsigned short pnode;
  3105. short memory_nid;
  3106. - spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  3107. + raw_spinlock_t nmi_lock; /* obsolete, see uv_hub_nmi */
  3108. unsigned long nmi_count; /* obsolete, see uv_hub_nmi */
  3109. };
  3110. extern struct uv_blade_info *uv_blade_info;
  3111. diff -Nur linux-4.1.6.orig/arch/x86/Kconfig linux-4.1.6/arch/x86/Kconfig
  3112. --- linux-4.1.6.orig/arch/x86/Kconfig 2015-08-17 05:52:51.000000000 +0200
  3113. +++ linux-4.1.6/arch/x86/Kconfig 2015-09-08 23:49:05.270181837 +0200
  3114. @@ -22,6 +22,7 @@
  3115. ### Arch settings
  3116. config X86
  3117. def_bool y
  3118. + select HAVE_PREEMPT_LAZY
  3119. select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
  3120. select ARCH_MIGHT_HAVE_ACPI_PDC if ACPI
  3121. select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
  3122. @@ -203,8 +204,11 @@
  3123. def_bool y
  3124. depends on ISA_DMA_API
  3125. +config RWSEM_GENERIC_SPINLOCK
  3126. + def_bool PREEMPT_RT_FULL
  3127. +
  3128. config RWSEM_XCHGADD_ALGORITHM
  3129. - def_bool y
  3130. + def_bool !RWSEM_GENERIC_SPINLOCK && !PREEMPT_RT_FULL
  3131. config GENERIC_CALIBRATE_DELAY
  3132. def_bool y
  3133. @@ -838,7 +842,7 @@
  3134. config MAXSMP
  3135. bool "Enable Maximum number of SMP Processors and NUMA Nodes"
  3136. depends on X86_64 && SMP && DEBUG_KERNEL
  3137. - select CPUMASK_OFFSTACK
  3138. + select CPUMASK_OFFSTACK if !PREEMPT_RT_FULL
  3139. ---help---
  3140. Enable maximum number of CPUS and NUMA Nodes for this architecture.
  3141. If unsure, say N.
  3142. diff -Nur linux-4.1.6.orig/arch/x86/kernel/apic/io_apic.c linux-4.1.6/arch/x86/kernel/apic/io_apic.c
  3143. --- linux-4.1.6.orig/arch/x86/kernel/apic/io_apic.c 2015-08-17 05:52:51.000000000 +0200
  3144. +++ linux-4.1.6/arch/x86/kernel/apic/io_apic.c 2015-09-08 23:49:05.518154339 +0200
  3145. @@ -1891,7 +1891,8 @@
  3146. static inline bool ioapic_irqd_mask(struct irq_data *data, struct irq_cfg *cfg)
  3147. {
  3148. /* If we are moving the irq we need to mask it */
  3149. - if (unlikely(irqd_is_setaffinity_pending(data))) {
  3150. + if (unlikely(irqd_is_setaffinity_pending(data) &&
  3151. + !irqd_irq_inprogress(data))) {
  3152. mask_ioapic(cfg);
  3153. return true;
  3154. }
  3155. diff -Nur linux-4.1.6.orig/arch/x86/kernel/apic/x2apic_uv_x.c linux-4.1.6/arch/x86/kernel/apic/x2apic_uv_x.c
  3156. --- linux-4.1.6.orig/arch/x86/kernel/apic/x2apic_uv_x.c 2015-08-17 05:52:51.000000000 +0200
  3157. +++ linux-4.1.6/arch/x86/kernel/apic/x2apic_uv_x.c 2015-09-08 23:49:05.518154339 +0200
  3158. @@ -949,7 +949,7 @@
  3159. uv_blade_info[blade].pnode = pnode;
  3160. uv_blade_info[blade].nr_possible_cpus = 0;
  3161. uv_blade_info[blade].nr_online_cpus = 0;
  3162. - spin_lock_init(&uv_blade_info[blade].nmi_lock);
  3163. + raw_spin_lock_init(&uv_blade_info[blade].nmi_lock);
  3164. min_pnode = min(pnode, min_pnode);
  3165. max_pnode = max(pnode, max_pnode);
  3166. blade++;
  3167. diff -Nur linux-4.1.6.orig/arch/x86/kernel/asm-offsets.c linux-4.1.6/arch/x86/kernel/asm-offsets.c
  3168. --- linux-4.1.6.orig/arch/x86/kernel/asm-offsets.c 2015-08-17 05:52:51.000000000 +0200
  3169. +++ linux-4.1.6/arch/x86/kernel/asm-offsets.c 2015-09-08 23:49:05.522153895 +0200
  3170. @@ -32,6 +32,7 @@
  3171. OFFSET(TI_flags, thread_info, flags);
  3172. OFFSET(TI_status, thread_info, status);
  3173. OFFSET(TI_addr_limit, thread_info, addr_limit);
  3174. + OFFSET(TI_preempt_lazy_count, thread_info, preempt_lazy_count);
  3175. BLANK();
  3176. OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
  3177. @@ -71,4 +72,5 @@
  3178. BLANK();
  3179. DEFINE(PTREGS_SIZE, sizeof(struct pt_regs));
  3180. + DEFINE(_PREEMPT_ENABLED, PREEMPT_ENABLED);
  3181. }
  3182. diff -Nur linux-4.1.6.orig/arch/x86/kernel/cpu/mcheck/mce.c linux-4.1.6/arch/x86/kernel/cpu/mcheck/mce.c
  3183. --- linux-4.1.6.orig/arch/x86/kernel/cpu/mcheck/mce.c 2015-08-17 05:52:51.000000000 +0200
  3184. +++ linux-4.1.6/arch/x86/kernel/cpu/mcheck/mce.c 2015-09-08 23:49:05.522153895 +0200
  3185. @@ -41,6 +41,8 @@
  3186. #include <linux/debugfs.h>
  3187. #include <linux/irq_work.h>
  3188. #include <linux/export.h>
  3189. +#include <linux/jiffies.h>
  3190. +#include <linux/work-simple.h>
  3191. #include <asm/processor.h>
  3192. #include <asm/traps.h>
  3193. @@ -1267,7 +1269,7 @@
  3194. static unsigned long check_interval = INITIAL_CHECK_INTERVAL;
  3195. static DEFINE_PER_CPU(unsigned long, mce_next_interval); /* in jiffies */
  3196. -static DEFINE_PER_CPU(struct timer_list, mce_timer);
  3197. +static DEFINE_PER_CPU(struct hrtimer, mce_timer);
  3198. static unsigned long mce_adjust_timer_default(unsigned long interval)
  3199. {
  3200. @@ -1276,32 +1278,18 @@
  3201. static unsigned long (*mce_adjust_timer)(unsigned long interval) = mce_adjust_timer_default;
  3202. -static void __restart_timer(struct timer_list *t, unsigned long interval)
  3203. +static enum hrtimer_restart __restart_timer(struct hrtimer *timer, unsigned long interval)
  3204. {
  3205. - unsigned long when = jiffies + interval;
  3206. - unsigned long flags;
  3207. -
  3208. - local_irq_save(flags);
  3209. -
  3210. - if (timer_pending(t)) {
  3211. - if (time_before(when, t->expires))
  3212. - mod_timer_pinned(t, when);
  3213. - } else {
  3214. - t->expires = round_jiffies(when);
  3215. - add_timer_on(t, smp_processor_id());
  3216. - }
  3217. -
  3218. - local_irq_restore(flags);
  3219. + if (!interval)
  3220. + return HRTIMER_NORESTART;
  3221. + hrtimer_forward_now(timer, ns_to_ktime(jiffies_to_nsecs(interval)));
  3222. + return HRTIMER_RESTART;
  3223. }
  3224. -static void mce_timer_fn(unsigned long data)
  3225. +static enum hrtimer_restart mce_timer_fn(struct hrtimer *timer)
  3226. {
  3227. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3228. - int cpu = smp_processor_id();
  3229. unsigned long iv;
  3230. - WARN_ON(cpu != data);
  3231. -
  3232. iv = __this_cpu_read(mce_next_interval);
  3233. if (mce_available(this_cpu_ptr(&cpu_info))) {
  3234. @@ -1324,7 +1312,7 @@
  3235. done:
  3236. __this_cpu_write(mce_next_interval, iv);
  3237. - __restart_timer(t, iv);
  3238. + return __restart_timer(timer, iv);
  3239. }
  3240. /*
  3241. @@ -1332,7 +1320,7 @@
  3242. */
  3243. void mce_timer_kick(unsigned long interval)
  3244. {
  3245. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3246. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  3247. unsigned long iv = __this_cpu_read(mce_next_interval);
  3248. __restart_timer(t, interval);
  3249. @@ -1347,7 +1335,7 @@
  3250. int cpu;
  3251. for_each_online_cpu(cpu)
  3252. - del_timer_sync(&per_cpu(mce_timer, cpu));
  3253. + hrtimer_cancel(&per_cpu(mce_timer, cpu));
  3254. }
  3255. static void mce_do_trigger(struct work_struct *work)
  3256. @@ -1357,6 +1345,56 @@
  3257. static DECLARE_WORK(mce_trigger_work, mce_do_trigger);
  3258. +static void __mce_notify_work(struct swork_event *event)
  3259. +{
  3260. + /* Not more than two messages every minute */
  3261. + static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  3262. +
  3263. + /* wake processes polling /dev/mcelog */
  3264. + wake_up_interruptible(&mce_chrdev_wait);
  3265. +
  3266. + /*
  3267. + * There is no risk of missing notifications because
  3268. + * work_pending is always cleared before the function is
  3269. + * executed.
  3270. + */
  3271. + if (mce_helper[0] && !work_pending(&mce_trigger_work))
  3272. + schedule_work(&mce_trigger_work);
  3273. +
  3274. + if (__ratelimit(&ratelimit))
  3275. + pr_info(HW_ERR "Machine check events logged\n");
  3276. +}
  3277. +
  3278. +#ifdef CONFIG_PREEMPT_RT_FULL
  3279. +static bool notify_work_ready __read_mostly;
  3280. +static struct swork_event notify_work;
  3281. +
  3282. +static int mce_notify_work_init(void)
  3283. +{
  3284. + int err;
  3285. +
  3286. + err = swork_get();
  3287. + if (err)
  3288. + return err;
  3289. +
  3290. + INIT_SWORK(&notify_work, __mce_notify_work);
  3291. + notify_work_ready = true;
  3292. + return 0;
  3293. +}
  3294. +
  3295. +static void mce_notify_work(void)
  3296. +{
  3297. + if (notify_work_ready)
  3298. + swork_queue(&notify_work);
  3299. +}
  3300. +#else
  3301. +static void mce_notify_work(void)
  3302. +{
  3303. + __mce_notify_work(NULL);
  3304. +}
  3305. +static inline int mce_notify_work_init(void) { return 0; }
  3306. +#endif
  3307. +
  3308. /*
  3309. * Notify the user(s) about new machine check events.
  3310. * Can be called from interrupt context, but not from machine check/NMI
  3311. @@ -1364,19 +1402,8 @@
  3312. */
  3313. int mce_notify_irq(void)
  3314. {
  3315. - /* Not more than two messages every minute */
  3316. - static DEFINE_RATELIMIT_STATE(ratelimit, 60*HZ, 2);
  3317. -
  3318. if (test_and_clear_bit(0, &mce_need_notify)) {
  3319. - /* wake processes polling /dev/mcelog */
  3320. - wake_up_interruptible(&mce_chrdev_wait);
  3321. -
  3322. - if (mce_helper[0])
  3323. - schedule_work(&mce_trigger_work);
  3324. -
  3325. - if (__ratelimit(&ratelimit))
  3326. - pr_info(HW_ERR "Machine check events logged\n");
  3327. -
  3328. + mce_notify_work();
  3329. return 1;
  3330. }
  3331. return 0;
  3332. @@ -1649,7 +1676,7 @@
  3333. }
  3334. }
  3335. -static void mce_start_timer(unsigned int cpu, struct timer_list *t)
  3336. +static void mce_start_timer(unsigned int cpu, struct hrtimer *t)
  3337. {
  3338. unsigned long iv = check_interval * HZ;
  3339. @@ -1658,16 +1685,17 @@
  3340. per_cpu(mce_next_interval, cpu) = iv;
  3341. - t->expires = round_jiffies(jiffies + iv);
  3342. - add_timer_on(t, cpu);
  3343. + hrtimer_start_range_ns(t, ns_to_ktime(jiffies_to_usecs(iv) * 1000ULL),
  3344. + 0, HRTIMER_MODE_REL_PINNED);
  3345. }
  3346. static void __mcheck_cpu_init_timer(void)
  3347. {
  3348. - struct timer_list *t = this_cpu_ptr(&mce_timer);
  3349. + struct hrtimer *t = this_cpu_ptr(&mce_timer);
  3350. unsigned int cpu = smp_processor_id();
  3351. - setup_timer(t, mce_timer_fn, cpu);
  3352. + hrtimer_init(t, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  3353. + t->function = mce_timer_fn;
  3354. mce_start_timer(cpu, t);
  3355. }
  3356. @@ -2345,6 +2373,8 @@
  3357. if (!mce_available(raw_cpu_ptr(&cpu_info)))
  3358. return;
  3359. + hrtimer_cancel(this_cpu_ptr(&mce_timer));
  3360. +
  3361. if (!(action & CPU_TASKS_FROZEN))
  3362. cmci_clear();
  3363. for (i = 0; i < mca_cfg.banks; i++) {
  3364. @@ -2371,6 +2401,7 @@
  3365. if (b->init)
  3366. wrmsrl(MSR_IA32_MCx_CTL(i), b->ctl);
  3367. }
  3368. + __mcheck_cpu_init_timer();
  3369. }
  3370. /* Get notified when a cpu comes on/off. Be hotplug friendly. */
  3371. @@ -2378,7 +2409,6 @@
  3372. mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
  3373. {
  3374. unsigned int cpu = (unsigned long)hcpu;
  3375. - struct timer_list *t = &per_cpu(mce_timer, cpu);
  3376. switch (action & ~CPU_TASKS_FROZEN) {
  3377. case CPU_ONLINE:
  3378. @@ -2398,11 +2428,9 @@
  3379. break;
  3380. case CPU_DOWN_PREPARE:
  3381. smp_call_function_single(cpu, mce_disable_cpu, &action, 1);
  3382. - del_timer_sync(t);
  3383. break;
  3384. case CPU_DOWN_FAILED:
  3385. smp_call_function_single(cpu, mce_reenable_cpu, &action, 1);
  3386. - mce_start_timer(cpu, t);
  3387. break;
  3388. }
  3389. @@ -2441,6 +2469,10 @@
  3390. goto err_out;
  3391. }
  3392. + err = mce_notify_work_init();
  3393. + if (err)
  3394. + goto err_out;
  3395. +
  3396. if (!zalloc_cpumask_var(&mce_device_initialized, GFP_KERNEL)) {
  3397. err = -ENOMEM;
  3398. goto err_out;
  3399. diff -Nur linux-4.1.6.orig/arch/x86/kernel/dumpstack_32.c linux-4.1.6/arch/x86/kernel/dumpstack_32.c
  3400. --- linux-4.1.6.orig/arch/x86/kernel/dumpstack_32.c 2015-08-17 05:52:51.000000000 +0200
  3401. +++ linux-4.1.6/arch/x86/kernel/dumpstack_32.c 2015-09-08 23:49:05.526153452 +0200
  3402. @@ -42,7 +42,7 @@
  3403. unsigned long *stack, unsigned long bp,
  3404. const struct stacktrace_ops *ops, void *data)
  3405. {
  3406. - const unsigned cpu = get_cpu();
  3407. + const unsigned cpu = get_cpu_light();
  3408. int graph = 0;
  3409. u32 *prev_esp;
  3410. @@ -86,7 +86,7 @@
  3411. break;
  3412. touch_nmi_watchdog();
  3413. }
  3414. - put_cpu();
  3415. + put_cpu_light();
  3416. }
  3417. EXPORT_SYMBOL(dump_trace);
  3418. diff -Nur linux-4.1.6.orig/arch/x86/kernel/dumpstack_64.c linux-4.1.6/arch/x86/kernel/dumpstack_64.c
  3419. --- linux-4.1.6.orig/arch/x86/kernel/dumpstack_64.c 2015-08-17 05:52:51.000000000 +0200
  3420. +++ linux-4.1.6/arch/x86/kernel/dumpstack_64.c 2015-09-08 23:49:05.526153452 +0200
  3421. @@ -152,7 +152,7 @@
  3422. unsigned long *stack, unsigned long bp,
  3423. const struct stacktrace_ops *ops, void *data)
  3424. {
  3425. - const unsigned cpu = get_cpu();
  3426. + const unsigned cpu = get_cpu_light();
  3427. struct thread_info *tinfo;
  3428. unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
  3429. unsigned long dummy;
  3430. @@ -241,7 +241,7 @@
  3431. * This handles the process stack:
  3432. */
  3433. bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
  3434. - put_cpu();
  3435. + put_cpu_light();
  3436. }
  3437. EXPORT_SYMBOL(dump_trace);
  3438. @@ -255,7 +255,7 @@
  3439. int cpu;
  3440. int i;
  3441. - preempt_disable();
  3442. + migrate_disable();
  3443. cpu = smp_processor_id();
  3444. irq_stack_end = (unsigned long *)(per_cpu(irq_stack_ptr, cpu));
  3445. @@ -291,7 +291,7 @@
  3446. pr_cont(" %016lx", *stack++);
  3447. touch_nmi_watchdog();
  3448. }
  3449. - preempt_enable();
  3450. + migrate_enable();
  3451. pr_cont("\n");
  3452. show_trace_log_lvl(task, regs, sp, bp, log_lvl);
  3453. diff -Nur linux-4.1.6.orig/arch/x86/kernel/entry_32.S linux-4.1.6/arch/x86/kernel/entry_32.S
  3454. --- linux-4.1.6.orig/arch/x86/kernel/entry_32.S 2015-08-17 05:52:51.000000000 +0200
  3455. +++ linux-4.1.6/arch/x86/kernel/entry_32.S 2015-09-08 23:49:05.526153452 +0200
  3456. @@ -359,8 +359,24 @@
  3457. ENTRY(resume_kernel)
  3458. DISABLE_INTERRUPTS(CLBR_ANY)
  3459. need_resched:
  3460. + # preempt count == 0 + NEED_RS set?
  3461. cmpl $0,PER_CPU_VAR(__preempt_count)
  3462. +#ifndef CONFIG_PREEMPT_LAZY
  3463. jnz restore_all
  3464. +#else
  3465. + jz test_int_off
  3466. +
  3467. + # atleast preempt count == 0 ?
  3468. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  3469. + jne restore_all
  3470. +
  3471. + cmpl $0,TI_preempt_lazy_count(%ebp) # non-zero preempt_lazy_count ?
  3472. + jnz restore_all
  3473. +
  3474. + testl $_TIF_NEED_RESCHED_LAZY, TI_flags(%ebp)
  3475. + jz restore_all
  3476. +test_int_off:
  3477. +#endif
  3478. testl $X86_EFLAGS_IF,PT_EFLAGS(%esp) # interrupts off (exception path) ?
  3479. jz restore_all
  3480. call preempt_schedule_irq
  3481. @@ -594,7 +610,7 @@
  3482. ALIGN
  3483. RING0_PTREGS_FRAME # can't unwind into user space anyway
  3484. work_pending:
  3485. - testb $_TIF_NEED_RESCHED, %cl
  3486. + testl $_TIF_NEED_RESCHED_MASK, %ecx
  3487. jz work_notifysig
  3488. work_resched:
  3489. call schedule
  3490. @@ -607,7 +623,7 @@
  3491. andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
  3492. # than syscall tracing?
  3493. jz restore_all
  3494. - testb $_TIF_NEED_RESCHED, %cl
  3495. + testl $_TIF_NEED_RESCHED_MASK, %ecx
  3496. jnz work_resched
  3497. work_notifysig: # deal with pending signals and
  3498. diff -Nur linux-4.1.6.orig/arch/x86/kernel/entry_64.S linux-4.1.6/arch/x86/kernel/entry_64.S
  3499. --- linux-4.1.6.orig/arch/x86/kernel/entry_64.S 2015-08-17 05:52:51.000000000 +0200
  3500. +++ linux-4.1.6/arch/x86/kernel/entry_64.S 2015-09-08 23:49:05.530153010 +0200
  3501. @@ -370,8 +370,8 @@
  3502. /* First do a reschedule test. */
  3503. /* edx: work, edi: workmask */
  3504. int_careful:
  3505. - bt $TIF_NEED_RESCHED,%edx
  3506. - jnc int_very_careful
  3507. + testl $_TIF_NEED_RESCHED_MASK,%edx
  3508. + jz int_very_careful
  3509. TRACE_IRQS_ON
  3510. ENABLE_INTERRUPTS(CLBR_NONE)
  3511. pushq_cfi %rdi
  3512. @@ -776,7 +776,23 @@
  3513. bt $9,EFLAGS(%rsp) /* interrupts were off? */
  3514. jnc 1f
  3515. 0: cmpl $0,PER_CPU_VAR(__preempt_count)
  3516. +#ifndef CONFIG_PREEMPT_LAZY
  3517. jnz 1f
  3518. +#else
  3519. + jz do_preempt_schedule_irq
  3520. +
  3521. + # atleast preempt count == 0 ?
  3522. + cmpl $_PREEMPT_ENABLED,PER_CPU_VAR(__preempt_count)
  3523. + jnz 1f
  3524. +
  3525. + GET_THREAD_INFO(%rcx)
  3526. + cmpl $0, TI_preempt_lazy_count(%rcx)
  3527. + jnz 1f
  3528. +
  3529. + bt $TIF_NEED_RESCHED_LAZY,TI_flags(%rcx)
  3530. + jnc 1f
  3531. +do_preempt_schedule_irq:
  3532. +#endif
  3533. call preempt_schedule_irq
  3534. jmp 0b
  3535. 1:
  3536. @@ -844,8 +860,8 @@
  3537. /* edi: workmask, edx: work */
  3538. retint_careful:
  3539. CFI_RESTORE_STATE
  3540. - bt $TIF_NEED_RESCHED,%edx
  3541. - jnc retint_signal
  3542. + testl $_TIF_NEED_RESCHED_MASK,%edx
  3543. + jz retint_signal
  3544. TRACE_IRQS_ON
  3545. ENABLE_INTERRUPTS(CLBR_NONE)
  3546. pushq_cfi %rdi
  3547. @@ -1118,6 +1134,7 @@
  3548. jmp 2b
  3549. .previous
  3550. +#ifndef CONFIG_PREEMPT_RT_FULL
  3551. /* Call softirq on interrupt stack. Interrupts are off. */
  3552. ENTRY(do_softirq_own_stack)
  3553. CFI_STARTPROC
  3554. @@ -1137,6 +1154,7 @@
  3555. ret
  3556. CFI_ENDPROC
  3557. END(do_softirq_own_stack)
  3558. +#endif
  3559. #ifdef CONFIG_XEN
  3560. idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
  3561. diff -Nur linux-4.1.6.orig/arch/x86/kernel/irq_32.c linux-4.1.6/arch/x86/kernel/irq_32.c
  3562. --- linux-4.1.6.orig/arch/x86/kernel/irq_32.c 2015-08-17 05:52:51.000000000 +0200
  3563. +++ linux-4.1.6/arch/x86/kernel/irq_32.c 2015-09-08 23:49:05.530153010 +0200
  3564. @@ -135,6 +135,7 @@
  3565. cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
  3566. }
  3567. +#ifndef CONFIG_PREEMPT_RT_FULL
  3568. void do_softirq_own_stack(void)
  3569. {
  3570. struct thread_info *curstk;
  3571. @@ -153,6 +154,7 @@
  3572. call_on_stack(__do_softirq, isp);
  3573. }
  3574. +#endif
  3575. bool handle_irq(unsigned irq, struct pt_regs *regs)
  3576. {
  3577. diff -Nur linux-4.1.6.orig/arch/x86/kernel/process_32.c linux-4.1.6/arch/x86/kernel/process_32.c
  3578. --- linux-4.1.6.orig/arch/x86/kernel/process_32.c 2015-08-17 05:52:51.000000000 +0200
  3579. +++ linux-4.1.6/arch/x86/kernel/process_32.c 2015-09-08 23:49:05.530153010 +0200
  3580. @@ -35,6 +35,7 @@
  3581. #include <linux/uaccess.h>
  3582. #include <linux/io.h>
  3583. #include <linux/kdebug.h>
  3584. +#include <linux/highmem.h>
  3585. #include <asm/pgtable.h>
  3586. #include <asm/ldt.h>
  3587. @@ -210,6 +211,35 @@
  3588. }
  3589. EXPORT_SYMBOL_GPL(start_thread);
  3590. +#ifdef CONFIG_PREEMPT_RT_FULL
  3591. +static void switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p)
  3592. +{
  3593. + int i;
  3594. +
  3595. + /*
  3596. + * Clear @prev's kmap_atomic mappings
  3597. + */
  3598. + for (i = 0; i < prev_p->kmap_idx; i++) {
  3599. + int idx = i + KM_TYPE_NR * smp_processor_id();
  3600. + pte_t *ptep = kmap_pte - idx;
  3601. +
  3602. + kpte_clear_flush(ptep, __fix_to_virt(FIX_KMAP_BEGIN + idx));
  3603. + }
  3604. + /*
  3605. + * Restore @next_p's kmap_atomic mappings
  3606. + */
  3607. + for (i = 0; i < next_p->kmap_idx; i++) {
  3608. + int idx = i + KM_TYPE_NR * smp_processor_id();
  3609. +
  3610. + if (!pte_none(next_p->kmap_pte[i]))
  3611. + set_pte(kmap_pte - idx, next_p->kmap_pte[i]);
  3612. + }
  3613. +}
  3614. +#else
  3615. +static inline void
  3616. +switch_kmaps(struct task_struct *prev_p, struct task_struct *next_p) { }
  3617. +#endif
  3618. +
  3619. /*
  3620. * switch_to(x,y) should switch tasks from x to y.
  3621. @@ -292,6 +322,8 @@
  3622. task_thread_info(next_p)->flags & _TIF_WORK_CTXSW_NEXT))
  3623. __switch_to_xtra(prev_p, next_p, tss);
  3624. + switch_kmaps(prev_p, next_p);
  3625. +
  3626. /*
  3627. * Leave lazy mode, flushing any hypercalls made here.
  3628. * This must be done before restoring TLS segments so
  3629. diff -Nur linux-4.1.6.orig/arch/x86/kernel/signal.c linux-4.1.6/arch/x86/kernel/signal.c
  3630. --- linux-4.1.6.orig/arch/x86/kernel/signal.c 2015-08-17 05:52:51.000000000 +0200
  3631. +++ linux-4.1.6/arch/x86/kernel/signal.c 2015-09-08 23:49:05.534152567 +0200
  3632. @@ -727,6 +727,14 @@
  3633. {
  3634. user_exit();
  3635. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  3636. + if (unlikely(current->forced_info.si_signo)) {
  3637. + struct task_struct *t = current;
  3638. + force_sig_info(t->forced_info.si_signo, &t->forced_info, t);
  3639. + t->forced_info.si_signo = 0;
  3640. + }
  3641. +#endif
  3642. +
  3643. if (thread_info_flags & _TIF_UPROBE)
  3644. uprobe_notify_resume(regs);
  3645. diff -Nur linux-4.1.6.orig/arch/x86/kernel/traps.c linux-4.1.6/arch/x86/kernel/traps.c
  3646. --- linux-4.1.6.orig/arch/x86/kernel/traps.c 2015-08-17 05:52:51.000000000 +0200
  3647. +++ linux-4.1.6/arch/x86/kernel/traps.c 2015-09-08 23:49:05.534152567 +0200
  3648. @@ -88,9 +88,21 @@
  3649. local_irq_enable();
  3650. }
  3651. -static inline void preempt_conditional_sti(struct pt_regs *regs)
  3652. +static inline void conditional_sti_ist(struct pt_regs *regs)
  3653. {
  3654. +#ifdef CONFIG_X86_64
  3655. + /*
  3656. + * X86_64 uses a per CPU stack on the IST for certain traps
  3657. + * like int3. The task can not be preempted when using one
  3658. + * of these stacks, thus preemption must be disabled, otherwise
  3659. + * the stack can be corrupted if the task is scheduled out,
  3660. + * and another task comes in and uses this stack.
  3661. + *
  3662. + * On x86_32 the task keeps its own stack and it is OK if the
  3663. + * task schedules out.
  3664. + */
  3665. preempt_count_inc();
  3666. +#endif
  3667. if (regs->flags & X86_EFLAGS_IF)
  3668. local_irq_enable();
  3669. }
  3670. @@ -101,11 +113,13 @@
  3671. local_irq_disable();
  3672. }
  3673. -static inline void preempt_conditional_cli(struct pt_regs *regs)
  3674. +static inline void conditional_cli_ist(struct pt_regs *regs)
  3675. {
  3676. if (regs->flags & X86_EFLAGS_IF)
  3677. local_irq_disable();
  3678. +#ifdef CONFIG_X86_64
  3679. preempt_count_dec();
  3680. +#endif
  3681. }
  3682. enum ctx_state ist_enter(struct pt_regs *regs)
  3683. @@ -536,9 +550,9 @@
  3684. * as we may switch to the interrupt stack.
  3685. */
  3686. debug_stack_usage_inc();
  3687. - preempt_conditional_sti(regs);
  3688. + conditional_sti_ist(regs);
  3689. do_trap(X86_TRAP_BP, SIGTRAP, "int3", regs, error_code, NULL);
  3690. - preempt_conditional_cli(regs);
  3691. + conditional_cli_ist(regs);
  3692. debug_stack_usage_dec();
  3693. exit:
  3694. ist_exit(regs, prev_state);
  3695. @@ -668,12 +682,12 @@
  3696. debug_stack_usage_inc();
  3697. /* It's safe to allow irq's after DR6 has been saved */
  3698. - preempt_conditional_sti(regs);
  3699. + conditional_sti_ist(regs);
  3700. if (v8086_mode(regs)) {
  3701. handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
  3702. X86_TRAP_DB);
  3703. - preempt_conditional_cli(regs);
  3704. + conditional_cli_ist(regs);
  3705. debug_stack_usage_dec();
  3706. goto exit;
  3707. }
  3708. @@ -693,7 +707,7 @@
  3709. si_code = get_si_code(tsk->thread.debugreg6);
  3710. if (tsk->thread.debugreg6 & (DR_STEP | DR_TRAP_BITS) || user_icebp)
  3711. send_sigtrap(tsk, regs, error_code, si_code);
  3712. - preempt_conditional_cli(regs);
  3713. + conditional_cli_ist(regs);
  3714. debug_stack_usage_dec();
  3715. exit:
  3716. diff -Nur linux-4.1.6.orig/arch/x86/kvm/lapic.c linux-4.1.6/arch/x86/kvm/lapic.c
  3717. --- linux-4.1.6.orig/arch/x86/kvm/lapic.c 2015-08-17 05:52:51.000000000 +0200
  3718. +++ linux-4.1.6/arch/x86/kvm/lapic.c 2015-09-08 23:49:05.534152567 +0200
  3719. @@ -1104,7 +1104,7 @@
  3720. static void apic_timer_expired(struct kvm_lapic *apic)
  3721. {
  3722. struct kvm_vcpu *vcpu = apic->vcpu;
  3723. - wait_queue_head_t *q = &vcpu->wq;
  3724. + struct swait_head *q = &vcpu->wq;
  3725. struct kvm_timer *ktimer = &apic->lapic_timer;
  3726. if (atomic_read(&apic->lapic_timer.pending))
  3727. @@ -1113,8 +1113,8 @@
  3728. atomic_inc(&apic->lapic_timer.pending);
  3729. kvm_set_pending_timer(vcpu);
  3730. - if (waitqueue_active(q))
  3731. - wake_up_interruptible(q);
  3732. + if (swaitqueue_active(q))
  3733. + swait_wake_interruptible(q);
  3734. if (apic_lvtt_tscdeadline(apic))
  3735. ktimer->expired_tscdeadline = ktimer->tscdeadline;
  3736. @@ -1167,8 +1167,36 @@
  3737. __delay(tsc_deadline - guest_tsc);
  3738. }
  3739. +static enum hrtimer_restart apic_timer_fn(struct hrtimer *data);
  3740. +
  3741. +static void __apic_timer_expired(struct hrtimer *data)
  3742. +{
  3743. + int ret, i = 0;
  3744. + enum hrtimer_restart r;
  3745. + struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
  3746. +
  3747. + r = apic_timer_fn(data);
  3748. +
  3749. + if (r == HRTIMER_RESTART) {
  3750. + do {
  3751. + ret = hrtimer_start_expires(data, HRTIMER_MODE_ABS);
  3752. + if (ret == -ETIME)
  3753. + hrtimer_add_expires_ns(&ktimer->timer,
  3754. + ktimer->period);
  3755. + i++;
  3756. + } while (ret == -ETIME && i < 10);
  3757. +
  3758. + if (ret == -ETIME) {
  3759. + printk_once(KERN_ERR "%s: failed to reprogram timer\n",
  3760. + __func__);
  3761. + WARN_ON_ONCE(1);
  3762. + }
  3763. + }
  3764. +}
  3765. +
  3766. static void start_apic_timer(struct kvm_lapic *apic)
  3767. {
  3768. + int ret;
  3769. ktime_t now;
  3770. atomic_set(&apic->lapic_timer.pending, 0);
  3771. @@ -1199,9 +1227,11 @@
  3772. }
  3773. }
  3774. - hrtimer_start(&apic->lapic_timer.timer,
  3775. + ret = hrtimer_start(&apic->lapic_timer.timer,
  3776. ktime_add_ns(now, apic->lapic_timer.period),
  3777. HRTIMER_MODE_ABS);
  3778. + if (ret == -ETIME)
  3779. + __apic_timer_expired(&apic->lapic_timer.timer);
  3780. apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
  3781. PRIx64 ", "
  3782. @@ -1233,8 +1263,10 @@
  3783. do_div(ns, this_tsc_khz);
  3784. expire = ktime_add_ns(now, ns);
  3785. expire = ktime_sub_ns(expire, lapic_timer_advance_ns);
  3786. - hrtimer_start(&apic->lapic_timer.timer,
  3787. + ret = hrtimer_start(&apic->lapic_timer.timer,
  3788. expire, HRTIMER_MODE_ABS);
  3789. + if (ret == -ETIME)
  3790. + __apic_timer_expired(&apic->lapic_timer.timer);
  3791. } else
  3792. apic_timer_expired(apic);
  3793. @@ -1707,6 +1739,7 @@
  3794. hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
  3795. HRTIMER_MODE_ABS);
  3796. apic->lapic_timer.timer.function = apic_timer_fn;
  3797. + apic->lapic_timer.timer.irqsafe = 1;
  3798. /*
  3799. * APIC is created enabled. This will prevent kvm_lapic_set_base from
  3800. @@ -1834,7 +1867,8 @@
  3801. timer = &vcpu->arch.apic->lapic_timer.timer;
  3802. if (hrtimer_cancel(timer))
  3803. - hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  3804. + if (hrtimer_start_expires(timer, HRTIMER_MODE_ABS) == -ETIME)
  3805. + __apic_timer_expired(timer);
  3806. }
  3807. /*
  3808. diff -Nur linux-4.1.6.orig/arch/x86/kvm/x86.c linux-4.1.6/arch/x86/kvm/x86.c
  3809. --- linux-4.1.6.orig/arch/x86/kvm/x86.c 2015-08-17 05:52:51.000000000 +0200
  3810. +++ linux-4.1.6/arch/x86/kvm/x86.c 2015-09-08 23:49:05.538152123 +0200
  3811. @@ -5813,6 +5813,13 @@
  3812. goto out;
  3813. }
  3814. +#ifdef CONFIG_PREEMPT_RT_FULL
  3815. + if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC)) {
  3816. + printk(KERN_ERR "RT requires X86_FEATURE_CONSTANT_TSC\n");
  3817. + return -EOPNOTSUPP;
  3818. + }
  3819. +#endif
  3820. +
  3821. r = kvm_mmu_module_init();
  3822. if (r)
  3823. goto out_free_percpu;
  3824. diff -Nur linux-4.1.6.orig/arch/x86/lib/usercopy_32.c linux-4.1.6/arch/x86/lib/usercopy_32.c
  3825. --- linux-4.1.6.orig/arch/x86/lib/usercopy_32.c 2015-08-17 05:52:51.000000000 +0200
  3826. +++ linux-4.1.6/arch/x86/lib/usercopy_32.c 2015-09-08 23:49:05.754128173 +0200
  3827. @@ -647,7 +647,8 @@
  3828. * @from: Source address, in kernel space.
  3829. * @n: Number of bytes to copy.
  3830. *
  3831. - * Context: User context only. This function may sleep.
  3832. + * Context: User context only. This function may sleep if pagefaults are
  3833. + * enabled.
  3834. *
  3835. * Copy data from kernel space to user space.
  3836. *
  3837. @@ -668,7 +669,8 @@
  3838. * @from: Source address, in user space.
  3839. * @n: Number of bytes to copy.
  3840. *
  3841. - * Context: User context only. This function may sleep.
  3842. + * Context: User context only. This function may sleep if pagefaults are
  3843. + * enabled.
  3844. *
  3845. * Copy data from user space to kernel space.
  3846. *
  3847. diff -Nur linux-4.1.6.orig/arch/x86/mm/fault.c linux-4.1.6/arch/x86/mm/fault.c
  3848. --- linux-4.1.6.orig/arch/x86/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  3849. +++ linux-4.1.6/arch/x86/mm/fault.c 2015-09-08 23:49:05.754128173 +0200
  3850. @@ -13,6 +13,7 @@
  3851. #include <linux/hugetlb.h> /* hstate_index_to_shift */
  3852. #include <linux/prefetch.h> /* prefetchw */
  3853. #include <linux/context_tracking.h> /* exception_enter(), ... */
  3854. +#include <linux/uaccess.h> /* faulthandler_disabled() */
  3855. #include <asm/traps.h> /* dotraplinkage, ... */
  3856. #include <asm/pgalloc.h> /* pgd_*(), ... */
  3857. @@ -1126,9 +1127,9 @@
  3858. /*
  3859. * If we're in an interrupt, have no user context or are running
  3860. - * in an atomic region then we must not take the fault:
  3861. + * in a region with pagefaults disabled then we must not take the fault
  3862. */
  3863. - if (unlikely(in_atomic() || !mm)) {
  3864. + if (unlikely(faulthandler_disabled() || !mm)) {
  3865. bad_area_nosemaphore(regs, error_code, address);
  3866. return;
  3867. }
  3868. diff -Nur linux-4.1.6.orig/arch/x86/mm/highmem_32.c linux-4.1.6/arch/x86/mm/highmem_32.c
  3869. --- linux-4.1.6.orig/arch/x86/mm/highmem_32.c 2015-08-17 05:52:51.000000000 +0200
  3870. +++ linux-4.1.6/arch/x86/mm/highmem_32.c 2015-09-08 23:49:05.754128173 +0200
  3871. @@ -32,10 +32,11 @@
  3872. */
  3873. void *kmap_atomic_prot(struct page *page, pgprot_t prot)
  3874. {
  3875. + pte_t pte = mk_pte(page, prot);
  3876. unsigned long vaddr;
  3877. int idx, type;
  3878. - /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
  3879. + preempt_disable_nort();
  3880. pagefault_disable();
  3881. if (!PageHighMem(page))
  3882. @@ -45,7 +46,10 @@
  3883. idx = type + KM_TYPE_NR*smp_processor_id();
  3884. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  3885. BUG_ON(!pte_none(*(kmap_pte-idx)));
  3886. - set_pte(kmap_pte-idx, mk_pte(page, prot));
  3887. +#ifdef CONFIG_PREEMPT_RT_FULL
  3888. + current->kmap_pte[type] = pte;
  3889. +#endif
  3890. + set_pte(kmap_pte-idx, pte);
  3891. arch_flush_lazy_mmu_mode();
  3892. return (void *)vaddr;
  3893. @@ -88,6 +92,9 @@
  3894. * is a bad idea also, in case the page changes cacheability
  3895. * attributes or becomes a protected page in a hypervisor.
  3896. */
  3897. +#ifdef CONFIG_PREEMPT_RT_FULL
  3898. + current->kmap_pte[type] = __pte(0);
  3899. +#endif
  3900. kpte_clear_flush(kmap_pte-idx, vaddr);
  3901. kmap_atomic_idx_pop();
  3902. arch_flush_lazy_mmu_mode();
  3903. @@ -100,6 +107,7 @@
  3904. #endif
  3905. pagefault_enable();
  3906. + preempt_enable_nort();
  3907. }
  3908. EXPORT_SYMBOL(__kunmap_atomic);
  3909. diff -Nur linux-4.1.6.orig/arch/x86/mm/iomap_32.c linux-4.1.6/arch/x86/mm/iomap_32.c
  3910. --- linux-4.1.6.orig/arch/x86/mm/iomap_32.c 2015-08-17 05:52:51.000000000 +0200
  3911. +++ linux-4.1.6/arch/x86/mm/iomap_32.c 2015-09-08 23:49:05.754128173 +0200
  3912. @@ -56,15 +56,22 @@
  3913. void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
  3914. {
  3915. + pte_t pte = pfn_pte(pfn, prot);
  3916. unsigned long vaddr;
  3917. int idx, type;
  3918. + preempt_disable();
  3919. pagefault_disable();
  3920. type = kmap_atomic_idx_push();
  3921. idx = type + KM_TYPE_NR * smp_processor_id();
  3922. vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
  3923. - set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
  3924. + WARN_ON(!pte_none(*(kmap_pte - idx)));
  3925. +
  3926. +#ifdef CONFIG_PREEMPT_RT_FULL
  3927. + current->kmap_pte[type] = pte;
  3928. +#endif
  3929. + set_pte(kmap_pte - idx, pte);
  3930. arch_flush_lazy_mmu_mode();
  3931. return (void *)vaddr;
  3932. @@ -112,10 +119,14 @@
  3933. * is a bad idea also, in case the page changes cacheability
  3934. * attributes or becomes a protected page in a hypervisor.
  3935. */
  3936. +#ifdef CONFIG_PREEMPT_RT_FULL
  3937. + current->kmap_pte[type] = __pte(0);
  3938. +#endif
  3939. kpte_clear_flush(kmap_pte-idx, vaddr);
  3940. kmap_atomic_idx_pop();
  3941. }
  3942. pagefault_enable();
  3943. + preempt_enable();
  3944. }
  3945. EXPORT_SYMBOL_GPL(iounmap_atomic);
  3946. diff -Nur linux-4.1.6.orig/arch/x86/platform/uv/tlb_uv.c linux-4.1.6/arch/x86/platform/uv/tlb_uv.c
  3947. --- linux-4.1.6.orig/arch/x86/platform/uv/tlb_uv.c 2015-08-17 05:52:51.000000000 +0200
  3948. +++ linux-4.1.6/arch/x86/platform/uv/tlb_uv.c 2015-09-08 23:49:05.758127730 +0200
  3949. @@ -714,9 +714,9 @@
  3950. quiesce_local_uvhub(hmaster);
  3951. - spin_lock(&hmaster->queue_lock);
  3952. + raw_spin_lock(&hmaster->queue_lock);
  3953. reset_with_ipi(&bau_desc->distribution, bcp);
  3954. - spin_unlock(&hmaster->queue_lock);
  3955. + raw_spin_unlock(&hmaster->queue_lock);
  3956. end_uvhub_quiesce(hmaster);
  3957. @@ -736,9 +736,9 @@
  3958. quiesce_local_uvhub(hmaster);
  3959. - spin_lock(&hmaster->queue_lock);
  3960. + raw_spin_lock(&hmaster->queue_lock);
  3961. reset_with_ipi(&bau_desc->distribution, bcp);
  3962. - spin_unlock(&hmaster->queue_lock);
  3963. + raw_spin_unlock(&hmaster->queue_lock);
  3964. end_uvhub_quiesce(hmaster);
  3965. @@ -759,7 +759,7 @@
  3966. cycles_t tm1;
  3967. hmaster = bcp->uvhub_master;
  3968. - spin_lock(&hmaster->disable_lock);
  3969. + raw_spin_lock(&hmaster->disable_lock);
  3970. if (!bcp->baudisabled) {
  3971. stat->s_bau_disabled++;
  3972. tm1 = get_cycles();
  3973. @@ -772,7 +772,7 @@
  3974. }
  3975. }
  3976. }
  3977. - spin_unlock(&hmaster->disable_lock);
  3978. + raw_spin_unlock(&hmaster->disable_lock);
  3979. }
  3980. static void count_max_concurr(int stat, struct bau_control *bcp,
  3981. @@ -835,7 +835,7 @@
  3982. */
  3983. static void uv1_throttle(struct bau_control *hmaster, struct ptc_stats *stat)
  3984. {
  3985. - spinlock_t *lock = &hmaster->uvhub_lock;
  3986. + raw_spinlock_t *lock = &hmaster->uvhub_lock;
  3987. atomic_t *v;
  3988. v = &hmaster->active_descriptor_count;
  3989. @@ -968,7 +968,7 @@
  3990. struct bau_control *hmaster;
  3991. hmaster = bcp->uvhub_master;
  3992. - spin_lock(&hmaster->disable_lock);
  3993. + raw_spin_lock(&hmaster->disable_lock);
  3994. if (bcp->baudisabled && (get_cycles() >= bcp->set_bau_on_time)) {
  3995. stat->s_bau_reenabled++;
  3996. for_each_present_cpu(tcpu) {
  3997. @@ -980,10 +980,10 @@
  3998. tbcp->period_giveups = 0;
  3999. }
  4000. }
  4001. - spin_unlock(&hmaster->disable_lock);
  4002. + raw_spin_unlock(&hmaster->disable_lock);
  4003. return 0;
  4004. }
  4005. - spin_unlock(&hmaster->disable_lock);
  4006. + raw_spin_unlock(&hmaster->disable_lock);
  4007. return -1;
  4008. }
  4009. @@ -1901,9 +1901,9 @@
  4010. bcp->cong_reps = congested_reps;
  4011. bcp->disabled_period = sec_2_cycles(disabled_period);
  4012. bcp->giveup_limit = giveup_limit;
  4013. - spin_lock_init(&bcp->queue_lock);
  4014. - spin_lock_init(&bcp->uvhub_lock);
  4015. - spin_lock_init(&bcp->disable_lock);
  4016. + raw_spin_lock_init(&bcp->queue_lock);
  4017. + raw_spin_lock_init(&bcp->uvhub_lock);
  4018. + raw_spin_lock_init(&bcp->disable_lock);
  4019. }
  4020. }
  4021. diff -Nur linux-4.1.6.orig/arch/x86/platform/uv/uv_time.c linux-4.1.6/arch/x86/platform/uv/uv_time.c
  4022. --- linux-4.1.6.orig/arch/x86/platform/uv/uv_time.c 2015-08-17 05:52:51.000000000 +0200
  4023. +++ linux-4.1.6/arch/x86/platform/uv/uv_time.c 2015-09-08 23:49:05.758127730 +0200
  4024. @@ -58,7 +58,7 @@
  4025. /* There is one of these allocated per node */
  4026. struct uv_rtc_timer_head {
  4027. - spinlock_t lock;
  4028. + raw_spinlock_t lock;
  4029. /* next cpu waiting for timer, local node relative: */
  4030. int next_cpu;
  4031. /* number of cpus on this node: */
  4032. @@ -178,7 +178,7 @@
  4033. uv_rtc_deallocate_timers();
  4034. return -ENOMEM;
  4035. }
  4036. - spin_lock_init(&head->lock);
  4037. + raw_spin_lock_init(&head->lock);
  4038. head->ncpus = uv_blade_nr_possible_cpus(bid);
  4039. head->next_cpu = -1;
  4040. blade_info[bid] = head;
  4041. @@ -232,7 +232,7 @@
  4042. unsigned long flags;
  4043. int next_cpu;
  4044. - spin_lock_irqsave(&head->lock, flags);
  4045. + raw_spin_lock_irqsave(&head->lock, flags);
  4046. next_cpu = head->next_cpu;
  4047. *t = expires;
  4048. @@ -244,12 +244,12 @@
  4049. if (uv_setup_intr(cpu, expires)) {
  4050. *t = ULLONG_MAX;
  4051. uv_rtc_find_next_timer(head, pnode);
  4052. - spin_unlock_irqrestore(&head->lock, flags);
  4053. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4054. return -ETIME;
  4055. }
  4056. }
  4057. - spin_unlock_irqrestore(&head->lock, flags);
  4058. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4059. return 0;
  4060. }
  4061. @@ -268,7 +268,7 @@
  4062. unsigned long flags;
  4063. int rc = 0;
  4064. - spin_lock_irqsave(&head->lock, flags);
  4065. + raw_spin_lock_irqsave(&head->lock, flags);
  4066. if ((head->next_cpu == bcpu && uv_read_rtc(NULL) >= *t) || force)
  4067. rc = 1;
  4068. @@ -280,7 +280,7 @@
  4069. uv_rtc_find_next_timer(head, pnode);
  4070. }
  4071. - spin_unlock_irqrestore(&head->lock, flags);
  4072. + raw_spin_unlock_irqrestore(&head->lock, flags);
  4073. return rc;
  4074. }
  4075. @@ -300,13 +300,18 @@
  4076. static cycle_t uv_read_rtc(struct clocksource *cs)
  4077. {
  4078. unsigned long offset;
  4079. + cycle_t cycles;
  4080. + preempt_disable();
  4081. if (uv_get_min_hub_revision_id() == 1)
  4082. offset = 0;
  4083. else
  4084. offset = (uv_blade_processor_id() * L1_CACHE_BYTES) % PAGE_SIZE;
  4085. - return (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  4086. + cycles = (cycle_t)uv_read_local_mmr(UVH_RTC | offset);
  4087. + preempt_enable();
  4088. +
  4089. + return cycles;
  4090. }
  4091. /*
  4092. diff -Nur linux-4.1.6.orig/arch/xtensa/mm/fault.c linux-4.1.6/arch/xtensa/mm/fault.c
  4093. --- linux-4.1.6.orig/arch/xtensa/mm/fault.c 2015-08-17 05:52:51.000000000 +0200
  4094. +++ linux-4.1.6/arch/xtensa/mm/fault.c 2015-09-08 23:49:05.758127730 +0200
  4095. @@ -15,10 +15,10 @@
  4096. #include <linux/mm.h>
  4097. #include <linux/module.h>
  4098. #include <linux/hardirq.h>
  4099. +#include <linux/uaccess.h>
  4100. #include <asm/mmu_context.h>
  4101. #include <asm/cacheflush.h>
  4102. #include <asm/hardirq.h>
  4103. -#include <asm/uaccess.h>
  4104. #include <asm/pgalloc.h>
  4105. DEFINE_PER_CPU(unsigned long, asid_cache) = ASID_USER_FIRST;
  4106. @@ -57,7 +57,7 @@
  4107. /* If we're in an interrupt or have no user
  4108. * context, we must not take the fault..
  4109. */
  4110. - if (in_atomic() || !mm) {
  4111. + if (faulthandler_disabled() || !mm) {
  4112. bad_page_fault(regs, address, SIGSEGV);
  4113. return;
  4114. }
  4115. diff -Nur linux-4.1.6.orig/arch/xtensa/mm/highmem.c linux-4.1.6/arch/xtensa/mm/highmem.c
  4116. --- linux-4.1.6.orig/arch/xtensa/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  4117. +++ linux-4.1.6/arch/xtensa/mm/highmem.c 2015-09-08 23:49:05.758127730 +0200
  4118. @@ -42,6 +42,7 @@
  4119. enum fixed_addresses idx;
  4120. unsigned long vaddr;
  4121. + preempt_disable();
  4122. pagefault_disable();
  4123. if (!PageHighMem(page))
  4124. return page_address(page);
  4125. @@ -79,6 +80,7 @@
  4126. }
  4127. pagefault_enable();
  4128. + preempt_enable();
  4129. }
  4130. EXPORT_SYMBOL(__kunmap_atomic);
  4131. diff -Nur linux-4.1.6.orig/block/blk-core.c linux-4.1.6/block/blk-core.c
  4132. --- linux-4.1.6.orig/block/blk-core.c 2015-08-17 05:52:51.000000000 +0200
  4133. +++ linux-4.1.6/block/blk-core.c 2015-09-08 23:49:05.762127285 +0200
  4134. @@ -100,6 +100,9 @@
  4135. INIT_LIST_HEAD(&rq->queuelist);
  4136. INIT_LIST_HEAD(&rq->timeout_list);
  4137. +#ifdef CONFIG_PREEMPT_RT_FULL
  4138. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  4139. +#endif
  4140. rq->cpu = -1;
  4141. rq->q = q;
  4142. rq->__sector = (sector_t) -1;
  4143. @@ -194,7 +197,7 @@
  4144. **/
  4145. void blk_start_queue(struct request_queue *q)
  4146. {
  4147. - WARN_ON(!irqs_disabled());
  4148. + WARN_ON_NONRT(!irqs_disabled());
  4149. queue_flag_clear(QUEUE_FLAG_STOPPED, q);
  4150. __blk_run_queue(q);
  4151. @@ -661,7 +664,7 @@
  4152. q->bypass_depth = 1;
  4153. __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  4154. - init_waitqueue_head(&q->mq_freeze_wq);
  4155. + init_swait_head(&q->mq_freeze_wq);
  4156. if (blkcg_init_queue(q))
  4157. goto fail_bdi;
  4158. @@ -3077,7 +3080,7 @@
  4159. blk_run_queue_async(q);
  4160. else
  4161. __blk_run_queue(q);
  4162. - spin_unlock(q->queue_lock);
  4163. + spin_unlock_irq(q->queue_lock);
  4164. }
  4165. static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule)
  4166. @@ -3125,7 +3128,6 @@
  4167. void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule)
  4168. {
  4169. struct request_queue *q;
  4170. - unsigned long flags;
  4171. struct request *rq;
  4172. LIST_HEAD(list);
  4173. unsigned int depth;
  4174. @@ -3145,11 +3147,6 @@
  4175. q = NULL;
  4176. depth = 0;
  4177. - /*
  4178. - * Save and disable interrupts here, to avoid doing it for every
  4179. - * queue lock we have to take.
  4180. - */
  4181. - local_irq_save(flags);
  4182. while (!list_empty(&list)) {
  4183. rq = list_entry_rq(list.next);
  4184. list_del_init(&rq->queuelist);
  4185. @@ -3162,7 +3159,7 @@
  4186. queue_unplugged(q, depth, from_schedule);
  4187. q = rq->q;
  4188. depth = 0;
  4189. - spin_lock(q->queue_lock);
  4190. + spin_lock_irq(q->queue_lock);
  4191. }
  4192. /*
  4193. @@ -3189,8 +3186,6 @@
  4194. */
  4195. if (q)
  4196. queue_unplugged(q, depth, from_schedule);
  4197. -
  4198. - local_irq_restore(flags);
  4199. }
  4200. void blk_finish_plug(struct blk_plug *plug)
  4201. diff -Nur linux-4.1.6.orig/block/blk-ioc.c linux-4.1.6/block/blk-ioc.c
  4202. --- linux-4.1.6.orig/block/blk-ioc.c 2015-08-17 05:52:51.000000000 +0200
  4203. +++ linux-4.1.6/block/blk-ioc.c 2015-09-08 23:49:05.762127285 +0200
  4204. @@ -7,6 +7,7 @@
  4205. #include <linux/bio.h>
  4206. #include <linux/blkdev.h>
  4207. #include <linux/slab.h>
  4208. +#include <linux/delay.h>
  4209. #include "blk.h"
  4210. @@ -109,7 +110,7 @@
  4211. spin_unlock(q->queue_lock);
  4212. } else {
  4213. spin_unlock_irqrestore(&ioc->lock, flags);
  4214. - cpu_relax();
  4215. + cpu_chill();
  4216. spin_lock_irqsave_nested(&ioc->lock, flags, 1);
  4217. }
  4218. }
  4219. @@ -187,7 +188,7 @@
  4220. spin_unlock(icq->q->queue_lock);
  4221. } else {
  4222. spin_unlock_irqrestore(&ioc->lock, flags);
  4223. - cpu_relax();
  4224. + cpu_chill();
  4225. goto retry;
  4226. }
  4227. }
  4228. diff -Nur linux-4.1.6.orig/block/blk-iopoll.c linux-4.1.6/block/blk-iopoll.c
  4229. --- linux-4.1.6.orig/block/blk-iopoll.c 2015-08-17 05:52:51.000000000 +0200
  4230. +++ linux-4.1.6/block/blk-iopoll.c 2015-09-08 23:49:05.762127285 +0200
  4231. @@ -35,6 +35,7 @@
  4232. list_add_tail(&iop->list, this_cpu_ptr(&blk_cpu_iopoll));
  4233. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4234. local_irq_restore(flags);
  4235. + preempt_check_resched_rt();
  4236. }
  4237. EXPORT_SYMBOL(blk_iopoll_sched);
  4238. @@ -132,6 +133,7 @@
  4239. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4240. local_irq_enable();
  4241. + preempt_check_resched_rt();
  4242. }
  4243. /**
  4244. @@ -201,6 +203,7 @@
  4245. this_cpu_ptr(&blk_cpu_iopoll));
  4246. __raise_softirq_irqoff(BLOCK_IOPOLL_SOFTIRQ);
  4247. local_irq_enable();
  4248. + preempt_check_resched_rt();
  4249. }
  4250. return NOTIFY_OK;
  4251. diff -Nur linux-4.1.6.orig/block/blk-mq.c linux-4.1.6/block/blk-mq.c
  4252. --- linux-4.1.6.orig/block/blk-mq.c 2015-08-17 05:52:51.000000000 +0200
  4253. +++ linux-4.1.6/block/blk-mq.c 2015-09-08 23:49:05.762127285 +0200
  4254. @@ -88,7 +88,7 @@
  4255. if (!(gfp & __GFP_WAIT))
  4256. return -EBUSY;
  4257. - ret = wait_event_interruptible(q->mq_freeze_wq,
  4258. + ret = swait_event_interruptible(q->mq_freeze_wq,
  4259. !q->mq_freeze_depth || blk_queue_dying(q));
  4260. if (blk_queue_dying(q))
  4261. return -ENODEV;
  4262. @@ -107,7 +107,7 @@
  4263. struct request_queue *q =
  4264. container_of(ref, struct request_queue, mq_usage_counter);
  4265. - wake_up_all(&q->mq_freeze_wq);
  4266. + swait_wake_all(&q->mq_freeze_wq);
  4267. }
  4268. void blk_mq_freeze_queue_start(struct request_queue *q)
  4269. @@ -127,7 +127,7 @@
  4270. static void blk_mq_freeze_queue_wait(struct request_queue *q)
  4271. {
  4272. - wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
  4273. + swait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
  4274. }
  4275. /*
  4276. @@ -151,7 +151,7 @@
  4277. spin_unlock_irq(q->queue_lock);
  4278. if (wake) {
  4279. percpu_ref_reinit(&q->mq_usage_counter);
  4280. - wake_up_all(&q->mq_freeze_wq);
  4281. + swait_wake_all(&q->mq_freeze_wq);
  4282. }
  4283. }
  4284. EXPORT_SYMBOL_GPL(blk_mq_unfreeze_queue);
  4285. @@ -170,7 +170,7 @@
  4286. * dying, we need to ensure that processes currently waiting on
  4287. * the queue are notified as well.
  4288. */
  4289. - wake_up_all(&q->mq_freeze_wq);
  4290. + swait_wake_all(&q->mq_freeze_wq);
  4291. }
  4292. bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
  4293. @@ -217,6 +217,9 @@
  4294. rq->resid_len = 0;
  4295. rq->sense = NULL;
  4296. +#ifdef CONFIG_PREEMPT_RT_FULL
  4297. + INIT_WORK(&rq->work, __blk_mq_complete_request_remote_work);
  4298. +#endif
  4299. INIT_LIST_HEAD(&rq->timeout_list);
  4300. rq->timeout = 0;
  4301. @@ -346,6 +349,17 @@
  4302. }
  4303. EXPORT_SYMBOL(blk_mq_end_request);
  4304. +#ifdef CONFIG_PREEMPT_RT_FULL
  4305. +
  4306. +void __blk_mq_complete_request_remote_work(struct work_struct *work)
  4307. +{
  4308. + struct request *rq = container_of(work, struct request, work);
  4309. +
  4310. + rq->q->softirq_done_fn(rq);
  4311. +}
  4312. +
  4313. +#else
  4314. +
  4315. static void __blk_mq_complete_request_remote(void *data)
  4316. {
  4317. struct request *rq = data;
  4318. @@ -353,6 +367,8 @@
  4319. rq->q->softirq_done_fn(rq);
  4320. }
  4321. +#endif
  4322. +
  4323. static void blk_mq_ipi_complete_request(struct request *rq)
  4324. {
  4325. struct blk_mq_ctx *ctx = rq->mq_ctx;
  4326. @@ -364,19 +380,23 @@
  4327. return;
  4328. }
  4329. - cpu = get_cpu();
  4330. + cpu = get_cpu_light();
  4331. if (!test_bit(QUEUE_FLAG_SAME_FORCE, &rq->q->queue_flags))
  4332. shared = cpus_share_cache(cpu, ctx->cpu);
  4333. if (cpu != ctx->cpu && !shared && cpu_online(ctx->cpu)) {
  4334. +#ifdef CONFIG_PREEMPT_RT_FULL
  4335. + schedule_work_on(ctx->cpu, &rq->work);
  4336. +#else
  4337. rq->csd.func = __blk_mq_complete_request_remote;
  4338. rq->csd.info = rq;
  4339. rq->csd.flags = 0;
  4340. smp_call_function_single_async(ctx->cpu, &rq->csd);
  4341. +#endif
  4342. } else {
  4343. rq->q->softirq_done_fn(rq);
  4344. }
  4345. - put_cpu();
  4346. + put_cpu_light();
  4347. }
  4348. void __blk_mq_complete_request(struct request *rq)
  4349. @@ -905,14 +925,14 @@
  4350. return;
  4351. if (!async) {
  4352. - int cpu = get_cpu();
  4353. + int cpu = get_cpu_light();
  4354. if (cpumask_test_cpu(cpu, hctx->cpumask)) {
  4355. __blk_mq_run_hw_queue(hctx);
  4356. - put_cpu();
  4357. + put_cpu_light();
  4358. return;
  4359. }
  4360. - put_cpu();
  4361. + put_cpu_light();
  4362. }
  4363. kblockd_schedule_delayed_work_on(blk_mq_hctx_next_cpu(hctx),
  4364. @@ -1589,7 +1609,7 @@
  4365. {
  4366. struct blk_mq_hw_ctx *hctx = data;
  4367. - if (action == CPU_DEAD || action == CPU_DEAD_FROZEN)
  4368. + if (action == CPU_POST_DEAD)
  4369. return blk_mq_hctx_cpu_offline(hctx, cpu);
  4370. /*
  4371. diff -Nur linux-4.1.6.orig/block/blk-mq-cpu.c linux-4.1.6/block/blk-mq-cpu.c
  4372. --- linux-4.1.6.orig/block/blk-mq-cpu.c 2015-08-17 05:52:51.000000000 +0200
  4373. +++ linux-4.1.6/block/blk-mq-cpu.c 2015-09-08 23:49:05.762127285 +0200
  4374. @@ -16,7 +16,7 @@
  4375. #include "blk-mq.h"
  4376. static LIST_HEAD(blk_mq_cpu_notify_list);
  4377. -static DEFINE_RAW_SPINLOCK(blk_mq_cpu_notify_lock);
  4378. +static DEFINE_SPINLOCK(blk_mq_cpu_notify_lock);
  4379. static int blk_mq_main_cpu_notify(struct notifier_block *self,
  4380. unsigned long action, void *hcpu)
  4381. @@ -25,7 +25,10 @@
  4382. struct blk_mq_cpu_notifier *notify;
  4383. int ret = NOTIFY_OK;
  4384. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4385. + if (action != CPU_POST_DEAD)
  4386. + return NOTIFY_OK;
  4387. +
  4388. + spin_lock(&blk_mq_cpu_notify_lock);
  4389. list_for_each_entry(notify, &blk_mq_cpu_notify_list, list) {
  4390. ret = notify->notify(notify->data, action, cpu);
  4391. @@ -33,7 +36,7 @@
  4392. break;
  4393. }
  4394. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4395. + spin_unlock(&blk_mq_cpu_notify_lock);
  4396. return ret;
  4397. }
  4398. @@ -41,16 +44,16 @@
  4399. {
  4400. BUG_ON(!notifier->notify);
  4401. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4402. + spin_lock(&blk_mq_cpu_notify_lock);
  4403. list_add_tail(&notifier->list, &blk_mq_cpu_notify_list);
  4404. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4405. + spin_unlock(&blk_mq_cpu_notify_lock);
  4406. }
  4407. void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier)
  4408. {
  4409. - raw_spin_lock(&blk_mq_cpu_notify_lock);
  4410. + spin_lock(&blk_mq_cpu_notify_lock);
  4411. list_del(&notifier->list);
  4412. - raw_spin_unlock(&blk_mq_cpu_notify_lock);
  4413. + spin_unlock(&blk_mq_cpu_notify_lock);
  4414. }
  4415. void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
  4416. diff -Nur linux-4.1.6.orig/block/blk-mq.h linux-4.1.6/block/blk-mq.h
  4417. --- linux-4.1.6.orig/block/blk-mq.h 2015-08-17 05:52:51.000000000 +0200
  4418. +++ linux-4.1.6/block/blk-mq.h 2015-09-08 23:49:05.762127285 +0200
  4419. @@ -76,7 +76,10 @@
  4420. static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
  4421. unsigned int cpu)
  4422. {
  4423. - return per_cpu_ptr(q->queue_ctx, cpu);
  4424. + struct blk_mq_ctx *ctx;
  4425. +
  4426. + ctx = per_cpu_ptr(q->queue_ctx, cpu);
  4427. + return ctx;
  4428. }
  4429. /*
  4430. @@ -87,12 +90,12 @@
  4431. */
  4432. static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
  4433. {
  4434. - return __blk_mq_get_ctx(q, get_cpu());
  4435. + return __blk_mq_get_ctx(q, get_cpu_light());
  4436. }
  4437. static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
  4438. {
  4439. - put_cpu();
  4440. + put_cpu_light();
  4441. }
  4442. struct blk_mq_alloc_data {
  4443. diff -Nur linux-4.1.6.orig/block/blk-softirq.c linux-4.1.6/block/blk-softirq.c
  4444. --- linux-4.1.6.orig/block/blk-softirq.c 2015-08-17 05:52:51.000000000 +0200
  4445. +++ linux-4.1.6/block/blk-softirq.c 2015-09-08 23:49:05.762127285 +0200
  4446. @@ -51,6 +51,7 @@
  4447. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  4448. local_irq_restore(flags);
  4449. + preempt_check_resched_rt();
  4450. }
  4451. /*
  4452. @@ -93,6 +94,7 @@
  4453. this_cpu_ptr(&blk_cpu_done));
  4454. raise_softirq_irqoff(BLOCK_SOFTIRQ);
  4455. local_irq_enable();
  4456. + preempt_check_resched_rt();
  4457. }
  4458. return NOTIFY_OK;
  4459. @@ -150,6 +152,7 @@
  4460. goto do_local;
  4461. local_irq_restore(flags);
  4462. + preempt_check_resched_rt();
  4463. }
  4464. /**
  4465. diff -Nur linux-4.1.6.orig/block/bounce.c linux-4.1.6/block/bounce.c
  4466. --- linux-4.1.6.orig/block/bounce.c 2015-08-17 05:52:51.000000000 +0200
  4467. +++ linux-4.1.6/block/bounce.c 2015-09-08 23:49:05.762127285 +0200
  4468. @@ -54,11 +54,11 @@
  4469. unsigned long flags;
  4470. unsigned char *vto;
  4471. - local_irq_save(flags);
  4472. + local_irq_save_nort(flags);
  4473. vto = kmap_atomic(to->bv_page);
  4474. memcpy(vto + to->bv_offset, vfrom, to->bv_len);
  4475. kunmap_atomic(vto);
  4476. - local_irq_restore(flags);
  4477. + local_irq_restore_nort(flags);
  4478. }
  4479. #else /* CONFIG_HIGHMEM */
  4480. diff -Nur linux-4.1.6.orig/crypto/algapi.c linux-4.1.6/crypto/algapi.c
  4481. --- linux-4.1.6.orig/crypto/algapi.c 2015-08-17 05:52:51.000000000 +0200
  4482. +++ linux-4.1.6/crypto/algapi.c 2015-09-08 23:49:05.762127285 +0200
  4483. @@ -695,13 +695,13 @@
  4484. int crypto_register_notifier(struct notifier_block *nb)
  4485. {
  4486. - return blocking_notifier_chain_register(&crypto_chain, nb);
  4487. + return srcu_notifier_chain_register(&crypto_chain, nb);
  4488. }
  4489. EXPORT_SYMBOL_GPL(crypto_register_notifier);
  4490. int crypto_unregister_notifier(struct notifier_block *nb)
  4491. {
  4492. - return blocking_notifier_chain_unregister(&crypto_chain, nb);
  4493. + return srcu_notifier_chain_unregister(&crypto_chain, nb);
  4494. }
  4495. EXPORT_SYMBOL_GPL(crypto_unregister_notifier);
  4496. diff -Nur linux-4.1.6.orig/crypto/api.c linux-4.1.6/crypto/api.c
  4497. --- linux-4.1.6.orig/crypto/api.c 2015-08-17 05:52:51.000000000 +0200
  4498. +++ linux-4.1.6/crypto/api.c 2015-09-08 23:49:05.762127285 +0200
  4499. @@ -31,7 +31,7 @@
  4500. DECLARE_RWSEM(crypto_alg_sem);
  4501. EXPORT_SYMBOL_GPL(crypto_alg_sem);
  4502. -BLOCKING_NOTIFIER_HEAD(crypto_chain);
  4503. +SRCU_NOTIFIER_HEAD(crypto_chain);
  4504. EXPORT_SYMBOL_GPL(crypto_chain);
  4505. static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
  4506. @@ -236,10 +236,10 @@
  4507. {
  4508. int ok;
  4509. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  4510. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  4511. if (ok == NOTIFY_DONE) {
  4512. request_module("cryptomgr");
  4513. - ok = blocking_notifier_call_chain(&crypto_chain, val, v);
  4514. + ok = srcu_notifier_call_chain(&crypto_chain, val, v);
  4515. }
  4516. return ok;
  4517. diff -Nur linux-4.1.6.orig/crypto/internal.h linux-4.1.6/crypto/internal.h
  4518. --- linux-4.1.6.orig/crypto/internal.h 2015-08-17 05:52:51.000000000 +0200
  4519. +++ linux-4.1.6/crypto/internal.h 2015-09-08 23:49:05.762127285 +0200
  4520. @@ -48,7 +48,7 @@
  4521. extern struct list_head crypto_alg_list;
  4522. extern struct rw_semaphore crypto_alg_sem;
  4523. -extern struct blocking_notifier_head crypto_chain;
  4524. +extern struct srcu_notifier_head crypto_chain;
  4525. #ifdef CONFIG_PROC_FS
  4526. void __init crypto_init_proc(void);
  4527. @@ -142,7 +142,7 @@
  4528. static inline void crypto_notify(unsigned long val, void *v)
  4529. {
  4530. - blocking_notifier_call_chain(&crypto_chain, val, v);
  4531. + srcu_notifier_call_chain(&crypto_chain, val, v);
  4532. }
  4533. #endif /* _CRYPTO_INTERNAL_H */
  4534. diff -Nur linux-4.1.6.orig/Documentation/hwlat_detector.txt linux-4.1.6/Documentation/hwlat_detector.txt
  4535. --- linux-4.1.6.orig/Documentation/hwlat_detector.txt 1970-01-01 01:00:00.000000000 +0100
  4536. +++ linux-4.1.6/Documentation/hwlat_detector.txt 2015-09-08 23:49:03.494378758 +0200
  4537. @@ -0,0 +1,64 @@
  4538. +Introduction:
  4539. +-------------
  4540. +
  4541. +The module hwlat_detector is a special purpose kernel module that is used to
  4542. +detect large system latencies induced by the behavior of certain underlying
  4543. +hardware or firmware, independent of Linux itself. The code was developed
  4544. +originally to detect SMIs (System Management Interrupts) on x86 systems,
  4545. +however there is nothing x86 specific about this patchset. It was
  4546. +originally written for use by the "RT" patch since the Real Time
  4547. +kernel is highly latency sensitive.
  4548. +
  4549. +SMIs are usually not serviced by the Linux kernel, which typically does not
  4550. +even know that they are occuring. SMIs are instead are set up by BIOS code
  4551. +and are serviced by BIOS code, usually for "critical" events such as
  4552. +management of thermal sensors and fans. Sometimes though, SMIs are used for
  4553. +other tasks and those tasks can spend an inordinate amount of time in the
  4554. +handler (sometimes measured in milliseconds). Obviously this is a problem if
  4555. +you are trying to keep event service latencies down in the microsecond range.
  4556. +
  4557. +The hardware latency detector works by hogging all of the cpus for configurable
  4558. +amounts of time (by calling stop_machine()), polling the CPU Time Stamp Counter
  4559. +for some period, then looking for gaps in the TSC data. Any gap indicates a
  4560. +time when the polling was interrupted and since the machine is stopped and
  4561. +interrupts turned off the only thing that could do that would be an SMI.
  4562. +
  4563. +Note that the SMI detector should *NEVER* be used in a production environment.
  4564. +It is intended to be run manually to determine if the hardware platform has a
  4565. +problem with long system firmware service routines.
  4566. +
  4567. +Usage:
  4568. +------
  4569. +
  4570. +Loading the module hwlat_detector passing the parameter "enabled=1" (or by
  4571. +setting the "enable" entry in "hwlat_detector" debugfs toggled on) is the only
  4572. +step required to start the hwlat_detector. It is possible to redefine the
  4573. +threshold in microseconds (us) above which latency spikes will be taken
  4574. +into account (parameter "threshold=").
  4575. +
  4576. +Example:
  4577. +
  4578. + # modprobe hwlat_detector enabled=1 threshold=100
  4579. +
  4580. +After the module is loaded, it creates a directory named "hwlat_detector" under
  4581. +the debugfs mountpoint, "/debug/hwlat_detector" for this text. It is necessary
  4582. +to have debugfs mounted, which might be on /sys/debug on your system.
  4583. +
  4584. +The /debug/hwlat_detector interface contains the following files:
  4585. +
  4586. +count - number of latency spikes observed since last reset
  4587. +enable - a global enable/disable toggle (0/1), resets count
  4588. +max - maximum hardware latency actually observed (usecs)
  4589. +sample - a pipe from which to read current raw sample data
  4590. + in the format <timestamp> <latency observed usecs>
  4591. + (can be opened O_NONBLOCK for a single sample)
  4592. +threshold - minimum latency value to be considered (usecs)
  4593. +width - time period to sample with CPUs held (usecs)
  4594. + must be less than the total window size (enforced)
  4595. +window - total period of sampling, width being inside (usecs)
  4596. +
  4597. +By default we will set width to 500,000 and window to 1,000,000, meaning that
  4598. +we will sample every 1,000,000 usecs (1s) for 500,000 usecs (0.5s). If we
  4599. +observe any latencies that exceed the threshold (initially 100 usecs),
  4600. +then we write to a global sample ring buffer of 8K samples, which is
  4601. +consumed by reading from the "sample" (pipe) debugfs file interface.
  4602. diff -Nur linux-4.1.6.orig/Documentation/sysrq.txt linux-4.1.6/Documentation/sysrq.txt
  4603. --- linux-4.1.6.orig/Documentation/sysrq.txt 2015-08-17 05:52:51.000000000 +0200
  4604. +++ linux-4.1.6/Documentation/sysrq.txt 2015-09-08 23:49:03.494378758 +0200
  4605. @@ -59,10 +59,17 @@
  4606. On other - If you know of the key combos for other architectures, please
  4607. let me know so I can add them to this section.
  4608. -On all - write a character to /proc/sysrq-trigger. e.g.:
  4609. -
  4610. +On all - write a character to /proc/sysrq-trigger, e.g.:
  4611. echo t > /proc/sysrq-trigger
  4612. +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
  4613. + echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
  4614. + Send an ICMP echo request with this pattern plus the particular
  4615. + SysRq command key. Example:
  4616. + # ping -c1 -s57 -p0102030468
  4617. + will trigger the SysRq-H (help) command.
  4618. +
  4619. +
  4620. * What are the 'command' keys?
  4621. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4622. 'b' - Will immediately reboot the system without syncing or unmounting
  4623. diff -Nur linux-4.1.6.orig/Documentation/trace/histograms.txt linux-4.1.6/Documentation/trace/histograms.txt
  4624. --- linux-4.1.6.orig/Documentation/trace/histograms.txt 1970-01-01 01:00:00.000000000 +0100
  4625. +++ linux-4.1.6/Documentation/trace/histograms.txt 2015-09-08 23:49:03.498378314 +0200
  4626. @@ -0,0 +1,186 @@
  4627. + Using the Linux Kernel Latency Histograms
  4628. +
  4629. +
  4630. +This document gives a short explanation how to enable, configure and use
  4631. +latency histograms. Latency histograms are primarily relevant in the
  4632. +context of real-time enabled kernels (CONFIG_PREEMPT/CONFIG_PREEMPT_RT)
  4633. +and are used in the quality management of the Linux real-time
  4634. +capabilities.
  4635. +
  4636. +
  4637. +* Purpose of latency histograms
  4638. +
  4639. +A latency histogram continuously accumulates the frequencies of latency
  4640. +data. There are two types of histograms
  4641. +- potential sources of latencies
  4642. +- effective latencies
  4643. +
  4644. +
  4645. +* Potential sources of latencies
  4646. +
  4647. +Potential sources of latencies are code segments where interrupts,
  4648. +preemption or both are disabled (aka critical sections). To create
  4649. +histograms of potential sources of latency, the kernel stores the time
  4650. +stamp at the start of a critical section, determines the time elapsed
  4651. +when the end of the section is reached, and increments the frequency
  4652. +counter of that latency value - irrespective of whether any concurrently
  4653. +running process is affected by latency or not.
  4654. +- Configuration items (in the Kernel hacking/Tracers submenu)
  4655. + CONFIG_INTERRUPT_OFF_LATENCY
  4656. + CONFIG_PREEMPT_OFF_LATENCY
  4657. +
  4658. +
  4659. +* Effective latencies
  4660. +
  4661. +Effective latencies are actually occuring during wakeup of a process. To
  4662. +determine effective latencies, the kernel stores the time stamp when a
  4663. +process is scheduled to be woken up, and determines the duration of the
  4664. +wakeup time shortly before control is passed over to this process. Note
  4665. +that the apparent latency in user space may be somewhat longer, since the
  4666. +process may be interrupted after control is passed over to it but before
  4667. +the execution in user space takes place. Simply measuring the interval
  4668. +between enqueuing and wakeup may also not appropriate in cases when a
  4669. +process is scheduled as a result of a timer expiration. The timer may have
  4670. +missed its deadline, e.g. due to disabled interrupts, but this latency
  4671. +would not be registered. Therefore, the offsets of missed timers are
  4672. +recorded in a separate histogram. If both wakeup latency and missed timer
  4673. +offsets are configured and enabled, a third histogram may be enabled that
  4674. +records the overall latency as a sum of the timer latency, if any, and the
  4675. +wakeup latency. This histogram is called "timerandwakeup".
  4676. +- Configuration items (in the Kernel hacking/Tracers submenu)
  4677. + CONFIG_WAKEUP_LATENCY
  4678. + CONFIG_MISSED_TIMER_OFSETS
  4679. +
  4680. +
  4681. +* Usage
  4682. +
  4683. +The interface to the administration of the latency histograms is located
  4684. +in the debugfs file system. To mount it, either enter
  4685. +
  4686. +mount -t sysfs nodev /sys
  4687. +mount -t debugfs nodev /sys/kernel/debug
  4688. +
  4689. +from shell command line level, or add
  4690. +
  4691. +nodev /sys sysfs defaults 0 0
  4692. +nodev /sys/kernel/debug debugfs defaults 0 0
  4693. +
  4694. +to the file /etc/fstab. All latency histogram related files are then
  4695. +available in the directory /sys/kernel/debug/tracing/latency_hist. A
  4696. +particular histogram type is enabled by writing non-zero to the related
  4697. +variable in the /sys/kernel/debug/tracing/latency_hist/enable directory.
  4698. +Select "preemptirqsoff" for the histograms of potential sources of
  4699. +latencies and "wakeup" for histograms of effective latencies etc. The
  4700. +histogram data - one per CPU - are available in the files
  4701. +
  4702. +/sys/kernel/debug/tracing/latency_hist/preemptoff/CPUx
  4703. +/sys/kernel/debug/tracing/latency_hist/irqsoff/CPUx
  4704. +/sys/kernel/debug/tracing/latency_hist/preemptirqsoff/CPUx
  4705. +/sys/kernel/debug/tracing/latency_hist/wakeup/CPUx
  4706. +/sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio/CPUx
  4707. +/sys/kernel/debug/tracing/latency_hist/missed_timer_offsets/CPUx
  4708. +/sys/kernel/debug/tracing/latency_hist/timerandwakeup/CPUx
  4709. +
  4710. +The histograms are reset by writing non-zero to the file "reset" in a
  4711. +particular latency directory. To reset all latency data, use
  4712. +
  4713. +#!/bin/sh
  4714. +
  4715. +TRACINGDIR=/sys/kernel/debug/tracing
  4716. +HISTDIR=$TRACINGDIR/latency_hist
  4717. +
  4718. +if test -d $HISTDIR
  4719. +then
  4720. + cd $HISTDIR
  4721. + for i in `find . | grep /reset$`
  4722. + do
  4723. + echo 1 >$i
  4724. + done
  4725. +fi
  4726. +
  4727. +
  4728. +* Data format
  4729. +
  4730. +Latency data are stored with a resolution of one microsecond. The
  4731. +maximum latency is 10,240 microseconds. The data are only valid, if the
  4732. +overflow register is empty. Every output line contains the latency in
  4733. +microseconds in the first row and the number of samples in the second
  4734. +row. To display only lines with a positive latency count, use, for
  4735. +example,
  4736. +
  4737. +grep -v " 0$" /sys/kernel/debug/tracing/latency_hist/preemptoff/CPU0
  4738. +
  4739. +#Minimum latency: 0 microseconds.
  4740. +#Average latency: 0 microseconds.
  4741. +#Maximum latency: 25 microseconds.
  4742. +#Total samples: 3104770694
  4743. +#There are 0 samples greater or equal than 10240 microseconds
  4744. +#usecs samples
  4745. + 0 2984486876
  4746. + 1 49843506
  4747. + 2 58219047
  4748. + 3 5348126
  4749. + 4 2187960
  4750. + 5 3388262
  4751. + 6 959289
  4752. + 7 208294
  4753. + 8 40420
  4754. + 9 4485
  4755. + 10 14918
  4756. + 11 18340
  4757. + 12 25052
  4758. + 13 19455
  4759. + 14 5602
  4760. + 15 969
  4761. + 16 47
  4762. + 17 18
  4763. + 18 14
  4764. + 19 1
  4765. + 20 3
  4766. + 21 2
  4767. + 22 5
  4768. + 23 2
  4769. + 25 1
  4770. +
  4771. +
  4772. +* Wakeup latency of a selected process
  4773. +
  4774. +To only collect wakeup latency data of a particular process, write the
  4775. +PID of the requested process to
  4776. +
  4777. +/sys/kernel/debug/tracing/latency_hist/wakeup/pid
  4778. +
  4779. +PIDs are not considered, if this variable is set to 0.
  4780. +
  4781. +
  4782. +* Details of the process with the highest wakeup latency so far
  4783. +
  4784. +Selected data of the process that suffered from the highest wakeup
  4785. +latency that occurred in a particular CPU are available in the file
  4786. +
  4787. +/sys/kernel/debug/tracing/latency_hist/wakeup/max_latency-CPUx.
  4788. +
  4789. +In addition, other relevant system data at the time when the
  4790. +latency occurred are given.
  4791. +
  4792. +The format of the data is (all in one line):
  4793. +<PID> <Priority> <Latency> (<Timeroffset>) <Command> \
  4794. +<- <PID> <Priority> <Command> <Timestamp>
  4795. +
  4796. +The value of <Timeroffset> is only relevant in the combined timer
  4797. +and wakeup latency recording. In the wakeup recording, it is
  4798. +always 0, in the missed_timer_offsets recording, it is the same
  4799. +as <Latency>.
  4800. +
  4801. +When retrospectively searching for the origin of a latency and
  4802. +tracing was not enabled, it may be helpful to know the name and
  4803. +some basic data of the task that (finally) was switching to the
  4804. +late real-tlme task. In addition to the victim's data, also the
  4805. +data of the possible culprit are therefore displayed after the
  4806. +"<-" symbol.
  4807. +
  4808. +Finally, the timestamp of the time when the latency occurred
  4809. +in <seconds>.<microseconds> after the most recent system boot
  4810. +is provided.
  4811. +
  4812. +These data are also reset when the wakeup histogram is reset.
  4813. diff -Nur linux-4.1.6.orig/drivers/acpi/acpica/acglobal.h linux-4.1.6/drivers/acpi/acpica/acglobal.h
  4814. --- linux-4.1.6.orig/drivers/acpi/acpica/acglobal.h 2015-08-17 05:52:51.000000000 +0200
  4815. +++ linux-4.1.6/drivers/acpi/acpica/acglobal.h 2015-09-08 23:49:05.762127285 +0200
  4816. @@ -112,7 +112,7 @@
  4817. * interrupt level
  4818. */
  4819. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_gpe_lock); /* For GPE data structs and registers */
  4820. -ACPI_GLOBAL(acpi_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  4821. +ACPI_GLOBAL(acpi_raw_spinlock, acpi_gbl_hardware_lock); /* For ACPI H/W except GPE registers */
  4822. ACPI_GLOBAL(acpi_spinlock, acpi_gbl_reference_count_lock);
  4823. /* Mutex for _OSI support */
  4824. diff -Nur linux-4.1.6.orig/drivers/acpi/acpica/hwregs.c linux-4.1.6/drivers/acpi/acpica/hwregs.c
  4825. --- linux-4.1.6.orig/drivers/acpi/acpica/hwregs.c 2015-08-17 05:52:51.000000000 +0200
  4826. +++ linux-4.1.6/drivers/acpi/acpica/hwregs.c 2015-09-08 23:49:05.762127285 +0200
  4827. @@ -269,14 +269,14 @@
  4828. ACPI_BITMASK_ALL_FIXED_STATUS,
  4829. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  4830. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  4831. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  4832. /* Clear the fixed events in PM1 A/B */
  4833. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  4834. ACPI_BITMASK_ALL_FIXED_STATUS);
  4835. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  4836. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  4837. if (ACPI_FAILURE(status)) {
  4838. goto exit;
  4839. diff -Nur linux-4.1.6.orig/drivers/acpi/acpica/hwxface.c linux-4.1.6/drivers/acpi/acpica/hwxface.c
  4840. --- linux-4.1.6.orig/drivers/acpi/acpica/hwxface.c 2015-08-17 05:52:51.000000000 +0200
  4841. +++ linux-4.1.6/drivers/acpi/acpica/hwxface.c 2015-09-08 23:49:05.762127285 +0200
  4842. @@ -374,7 +374,7 @@
  4843. return_ACPI_STATUS(AE_BAD_PARAMETER);
  4844. }
  4845. - lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  4846. + raw_spin_lock_irqsave(acpi_gbl_hardware_lock, lock_flags);
  4847. /*
  4848. * At this point, we know that the parent register is one of the
  4849. @@ -435,7 +435,7 @@
  4850. unlock_and_exit:
  4851. - acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  4852. + raw_spin_unlock_irqrestore(acpi_gbl_hardware_lock, lock_flags);
  4853. return_ACPI_STATUS(status);
  4854. }
  4855. diff -Nur linux-4.1.6.orig/drivers/acpi/acpica/utmutex.c linux-4.1.6/drivers/acpi/acpica/utmutex.c
  4856. --- linux-4.1.6.orig/drivers/acpi/acpica/utmutex.c 2015-08-17 05:52:51.000000000 +0200
  4857. +++ linux-4.1.6/drivers/acpi/acpica/utmutex.c 2015-09-08 23:49:05.762127285 +0200
  4858. @@ -88,7 +88,7 @@
  4859. return_ACPI_STATUS (status);
  4860. }
  4861. - status = acpi_os_create_lock (&acpi_gbl_hardware_lock);
  4862. + status = acpi_os_create_raw_lock (&acpi_gbl_hardware_lock);
  4863. if (ACPI_FAILURE (status)) {
  4864. return_ACPI_STATUS (status);
  4865. }
  4866. @@ -141,7 +141,7 @@
  4867. /* Delete the spinlocks */
  4868. acpi_os_delete_lock(acpi_gbl_gpe_lock);
  4869. - acpi_os_delete_lock(acpi_gbl_hardware_lock);
  4870. + acpi_os_delete_raw_lock(acpi_gbl_hardware_lock);
  4871. acpi_os_delete_lock(acpi_gbl_reference_count_lock);
  4872. /* Delete the reader/writer lock */
  4873. diff -Nur linux-4.1.6.orig/drivers/ata/libata-sff.c linux-4.1.6/drivers/ata/libata-sff.c
  4874. --- linux-4.1.6.orig/drivers/ata/libata-sff.c 2015-08-17 05:52:51.000000000 +0200
  4875. +++ linux-4.1.6/drivers/ata/libata-sff.c 2015-09-08 23:49:05.762127285 +0200
  4876. @@ -678,9 +678,9 @@
  4877. unsigned long flags;
  4878. unsigned int consumed;
  4879. - local_irq_save(flags);
  4880. + local_irq_save_nort(flags);
  4881. consumed = ata_sff_data_xfer32(dev, buf, buflen, rw);
  4882. - local_irq_restore(flags);
  4883. + local_irq_restore_nort(flags);
  4884. return consumed;
  4885. }
  4886. @@ -719,7 +719,7 @@
  4887. unsigned long flags;
  4888. /* FIXME: use a bounce buffer */
  4889. - local_irq_save(flags);
  4890. + local_irq_save_nort(flags);
  4891. buf = kmap_atomic(page);
  4892. /* do the actual data transfer */
  4893. @@ -727,7 +727,7 @@
  4894. do_write);
  4895. kunmap_atomic(buf);
  4896. - local_irq_restore(flags);
  4897. + local_irq_restore_nort(flags);
  4898. } else {
  4899. buf = page_address(page);
  4900. ap->ops->sff_data_xfer(qc->dev, buf + offset, qc->sect_size,
  4901. @@ -864,7 +864,7 @@
  4902. unsigned long flags;
  4903. /* FIXME: use bounce buffer */
  4904. - local_irq_save(flags);
  4905. + local_irq_save_nort(flags);
  4906. buf = kmap_atomic(page);
  4907. /* do the actual data transfer */
  4908. @@ -872,7 +872,7 @@
  4909. count, rw);
  4910. kunmap_atomic(buf);
  4911. - local_irq_restore(flags);
  4912. + local_irq_restore_nort(flags);
  4913. } else {
  4914. buf = page_address(page);
  4915. consumed = ap->ops->sff_data_xfer(dev, buf + offset,
  4916. diff -Nur linux-4.1.6.orig/drivers/char/random.c linux-4.1.6/drivers/char/random.c
  4917. --- linux-4.1.6.orig/drivers/char/random.c 2015-08-17 05:52:51.000000000 +0200
  4918. +++ linux-4.1.6/drivers/char/random.c 2015-09-08 23:49:05.766126841 +0200
  4919. @@ -776,8 +776,6 @@
  4920. } sample;
  4921. long delta, delta2, delta3;
  4922. - preempt_disable();
  4923. -
  4924. sample.jiffies = jiffies;
  4925. sample.cycles = random_get_entropy();
  4926. sample.num = num;
  4927. @@ -818,7 +816,6 @@
  4928. */
  4929. credit_entropy_bits(r, min_t(int, fls(delta>>1), 11));
  4930. }
  4931. - preempt_enable();
  4932. }
  4933. void add_input_randomness(unsigned int type, unsigned int code,
  4934. @@ -871,28 +868,27 @@
  4935. return *(ptr + f->reg_idx++);
  4936. }
  4937. -void add_interrupt_randomness(int irq, int irq_flags)
  4938. +void add_interrupt_randomness(int irq, int irq_flags, __u64 ip)
  4939. {
  4940. struct entropy_store *r;
  4941. struct fast_pool *fast_pool = this_cpu_ptr(&irq_randomness);
  4942. - struct pt_regs *regs = get_irq_regs();
  4943. unsigned long now = jiffies;
  4944. cycles_t cycles = random_get_entropy();
  4945. __u32 c_high, j_high;
  4946. - __u64 ip;
  4947. unsigned long seed;
  4948. int credit = 0;
  4949. if (cycles == 0)
  4950. - cycles = get_reg(fast_pool, regs);
  4951. + cycles = get_reg(fast_pool, NULL);
  4952. c_high = (sizeof(cycles) > 4) ? cycles >> 32 : 0;
  4953. j_high = (sizeof(now) > 4) ? now >> 32 : 0;
  4954. fast_pool->pool[0] ^= cycles ^ j_high ^ irq;
  4955. fast_pool->pool[1] ^= now ^ c_high;
  4956. - ip = regs ? instruction_pointer(regs) : _RET_IP_;
  4957. + if (!ip)
  4958. + ip = _RET_IP_;
  4959. fast_pool->pool[2] ^= ip;
  4960. fast_pool->pool[3] ^= (sizeof(ip) > 4) ? ip >> 32 :
  4961. - get_reg(fast_pool, regs);
  4962. + get_reg(fast_pool, NULL);
  4963. fast_mix(fast_pool);
  4964. add_interrupt_bench(cycles);
  4965. diff -Nur linux-4.1.6.orig/drivers/clocksource/tcb_clksrc.c linux-4.1.6/drivers/clocksource/tcb_clksrc.c
  4966. --- linux-4.1.6.orig/drivers/clocksource/tcb_clksrc.c 2015-08-17 05:52:51.000000000 +0200
  4967. +++ linux-4.1.6/drivers/clocksource/tcb_clksrc.c 2015-09-08 23:49:05.766126841 +0200
  4968. @@ -23,8 +23,7 @@
  4969. * this 32 bit free-running counter. the second channel is not used.
  4970. *
  4971. * - The third channel may be used to provide a 16-bit clockevent
  4972. - * source, used in either periodic or oneshot mode. This runs
  4973. - * at 32 KiHZ, and can handle delays of up to two seconds.
  4974. + * source, used in either periodic or oneshot mode.
  4975. *
  4976. * A boot clocksource and clockevent source are also currently needed,
  4977. * unless the relevant platforms (ARM/AT91, AVR32/AT32) are changed so
  4978. @@ -74,6 +73,7 @@
  4979. struct tc_clkevt_device {
  4980. struct clock_event_device clkevt;
  4981. struct clk *clk;
  4982. + u32 freq;
  4983. void __iomem *regs;
  4984. };
  4985. @@ -82,13 +82,6 @@
  4986. return container_of(clkevt, struct tc_clkevt_device, clkevt);
  4987. }
  4988. -/* For now, we always use the 32K clock ... this optimizes for NO_HZ,
  4989. - * because using one of the divided clocks would usually mean the
  4990. - * tick rate can never be less than several dozen Hz (vs 0.5 Hz).
  4991. - *
  4992. - * A divided clock could be good for high resolution timers, since
  4993. - * 30.5 usec resolution can seem "low".
  4994. - */
  4995. static u32 timer_clock;
  4996. static void tc_mode(enum clock_event_mode m, struct clock_event_device *d)
  4997. @@ -111,11 +104,12 @@
  4998. case CLOCK_EVT_MODE_PERIODIC:
  4999. clk_enable(tcd->clk);
  5000. - /* slow clock, count up to RC, then irq and restart */
  5001. + /* count up to RC, then irq and restart */
  5002. __raw_writel(timer_clock
  5003. | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  5004. regs + ATMEL_TC_REG(2, CMR));
  5005. - __raw_writel((32768 + HZ/2) / HZ, tcaddr + ATMEL_TC_REG(2, RC));
  5006. + __raw_writel((tcd->freq + HZ / 2) / HZ,
  5007. + tcaddr + ATMEL_TC_REG(2, RC));
  5008. /* Enable clock and interrupts on RC compare */
  5009. __raw_writel(ATMEL_TC_CPCS, regs + ATMEL_TC_REG(2, IER));
  5010. @@ -128,7 +122,7 @@
  5011. case CLOCK_EVT_MODE_ONESHOT:
  5012. clk_enable(tcd->clk);
  5013. - /* slow clock, count up to RC, then irq and stop */
  5014. + /* count up to RC, then irq and stop */
  5015. __raw_writel(timer_clock | ATMEL_TC_CPCSTOP
  5016. | ATMEL_TC_WAVE | ATMEL_TC_WAVESEL_UP_AUTO,
  5017. regs + ATMEL_TC_REG(2, CMR));
  5018. @@ -157,8 +151,12 @@
  5019. .name = "tc_clkevt",
  5020. .features = CLOCK_EVT_FEAT_PERIODIC
  5021. | CLOCK_EVT_FEAT_ONESHOT,
  5022. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  5023. /* Should be lower than at91rm9200's system timer */
  5024. .rating = 125,
  5025. +#else
  5026. + .rating = 200,
  5027. +#endif
  5028. .set_next_event = tc_next_event,
  5029. .set_mode = tc_mode,
  5030. },
  5031. @@ -178,8 +176,9 @@
  5032. return IRQ_NONE;
  5033. }
  5034. -static int __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx)
  5035. +static int __init setup_clkevents(struct atmel_tc *tc, int divisor_idx)
  5036. {
  5037. + unsigned divisor = atmel_tc_divisors[divisor_idx];
  5038. int ret;
  5039. struct clk *t2_clk = tc->clk[2];
  5040. int irq = tc->irq[2];
  5041. @@ -193,7 +192,11 @@
  5042. clkevt.regs = tc->regs;
  5043. clkevt.clk = t2_clk;
  5044. - timer_clock = clk32k_divisor_idx;
  5045. + timer_clock = divisor_idx;
  5046. + if (!divisor)
  5047. + clkevt.freq = 32768;
  5048. + else
  5049. + clkevt.freq = clk_get_rate(t2_clk) / divisor;
  5050. clkevt.clkevt.cpumask = cpumask_of(0);
  5051. @@ -203,7 +206,7 @@
  5052. return ret;
  5053. }
  5054. - clockevents_config_and_register(&clkevt.clkevt, 32768, 1, 0xffff);
  5055. + clockevents_config_and_register(&clkevt.clkevt, clkevt.freq, 1, 0xffff);
  5056. return ret;
  5057. }
  5058. @@ -340,7 +343,11 @@
  5059. goto err_disable_t1;
  5060. /* channel 2: periodic and oneshot timer support */
  5061. +#ifdef CONFIG_ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  5062. ret = setup_clkevents(tc, clk32k_divisor_idx);
  5063. +#else
  5064. + ret = setup_clkevents(tc, best_divisor_idx);
  5065. +#endif
  5066. if (ret)
  5067. goto err_unregister_clksrc;
  5068. diff -Nur linux-4.1.6.orig/drivers/clocksource/timer-atmel-pit.c linux-4.1.6/drivers/clocksource/timer-atmel-pit.c
  5069. --- linux-4.1.6.orig/drivers/clocksource/timer-atmel-pit.c 2015-08-17 05:52:51.000000000 +0200
  5070. +++ linux-4.1.6/drivers/clocksource/timer-atmel-pit.c 2015-09-08 23:49:05.766126841 +0200
  5071. @@ -90,6 +90,7 @@
  5072. return elapsed;
  5073. }
  5074. +static struct irqaction at91sam926x_pit_irq;
  5075. /*
  5076. * Clockevent device: interrupts every 1/HZ (== pit_cycles * MCK/16)
  5077. */
  5078. @@ -100,6 +101,8 @@
  5079. switch (mode) {
  5080. case CLOCK_EVT_MODE_PERIODIC:
  5081. + /* Set up irq handler */
  5082. + setup_irq(at91sam926x_pit_irq.irq, &at91sam926x_pit_irq);
  5083. /* update clocksource counter */
  5084. data->cnt += data->cycle * PIT_PICNT(pit_read(data->base, AT91_PIT_PIVR));
  5085. pit_write(data->base, AT91_PIT_MR,
  5086. @@ -113,6 +116,7 @@
  5087. /* disable irq, leaving the clocksource active */
  5088. pit_write(data->base, AT91_PIT_MR,
  5089. (data->cycle - 1) | AT91_PIT_PITEN);
  5090. + remove_irq(at91sam926x_pit_irq.irq, &at91sam926x_pit_irq);
  5091. break;
  5092. case CLOCK_EVT_MODE_RESUME:
  5093. break;
  5094. diff -Nur linux-4.1.6.orig/drivers/clocksource/timer-atmel-st.c linux-4.1.6/drivers/clocksource/timer-atmel-st.c
  5095. --- linux-4.1.6.orig/drivers/clocksource/timer-atmel-st.c 2015-08-17 05:52:51.000000000 +0200
  5096. +++ linux-4.1.6/drivers/clocksource/timer-atmel-st.c 2015-09-08 23:49:05.766126841 +0200
  5097. @@ -131,6 +131,7 @@
  5098. break;
  5099. case CLOCK_EVT_MODE_SHUTDOWN:
  5100. case CLOCK_EVT_MODE_UNUSED:
  5101. + remove_irq(NR_IRQS_LEGACY + AT91_ID_SYS, &at91rm9200_timer_irq);
  5102. case CLOCK_EVT_MODE_RESUME:
  5103. irqmask = 0;
  5104. break;
  5105. diff -Nur linux-4.1.6.orig/drivers/cpufreq/cpufreq.c linux-4.1.6/drivers/cpufreq/cpufreq.c
  5106. --- linux-4.1.6.orig/drivers/cpufreq/cpufreq.c 2015-08-17 05:52:51.000000000 +0200
  5107. +++ linux-4.1.6/drivers/cpufreq/cpufreq.c 2015-09-08 23:49:05.818121077 +0200
  5108. @@ -64,12 +64,6 @@
  5109. return cpufreq_driver->target_index || cpufreq_driver->target;
  5110. }
  5111. -/*
  5112. - * rwsem to guarantee that cpufreq driver module doesn't unload during critical
  5113. - * sections
  5114. - */
  5115. -static DECLARE_RWSEM(cpufreq_rwsem);
  5116. -
  5117. /* internal prototypes */
  5118. static int __cpufreq_governor(struct cpufreq_policy *policy,
  5119. unsigned int event);
  5120. @@ -215,9 +209,6 @@
  5121. if (cpu >= nr_cpu_ids)
  5122. return NULL;
  5123. - if (!down_read_trylock(&cpufreq_rwsem))
  5124. - return NULL;
  5125. -
  5126. /* get the cpufreq driver */
  5127. read_lock_irqsave(&cpufreq_driver_lock, flags);
  5128. @@ -230,9 +221,6 @@
  5129. read_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5130. - if (!policy)
  5131. - up_read(&cpufreq_rwsem);
  5132. -
  5133. return policy;
  5134. }
  5135. EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
  5136. @@ -240,7 +228,6 @@
  5137. void cpufreq_cpu_put(struct cpufreq_policy *policy)
  5138. {
  5139. kobject_put(&policy->kobj);
  5140. - up_read(&cpufreq_rwsem);
  5141. }
  5142. EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
  5143. @@ -765,9 +752,6 @@
  5144. struct freq_attr *fattr = to_attr(attr);
  5145. ssize_t ret;
  5146. - if (!down_read_trylock(&cpufreq_rwsem))
  5147. - return -EINVAL;
  5148. -
  5149. down_read(&policy->rwsem);
  5150. if (fattr->show)
  5151. @@ -776,7 +760,6 @@
  5152. ret = -EIO;
  5153. up_read(&policy->rwsem);
  5154. - up_read(&cpufreq_rwsem);
  5155. return ret;
  5156. }
  5157. @@ -793,9 +776,6 @@
  5158. if (!cpu_online(policy->cpu))
  5159. goto unlock;
  5160. - if (!down_read_trylock(&cpufreq_rwsem))
  5161. - goto unlock;
  5162. -
  5163. down_write(&policy->rwsem);
  5164. if (fattr->store)
  5165. @@ -804,8 +784,6 @@
  5166. ret = -EIO;
  5167. up_write(&policy->rwsem);
  5168. -
  5169. - up_read(&cpufreq_rwsem);
  5170. unlock:
  5171. put_online_cpus();
  5172. @@ -1117,16 +1095,12 @@
  5173. if (unlikely(policy))
  5174. return 0;
  5175. - if (!down_read_trylock(&cpufreq_rwsem))
  5176. - return 0;
  5177. -
  5178. /* Check if this cpu was hot-unplugged earlier and has siblings */
  5179. read_lock_irqsave(&cpufreq_driver_lock, flags);
  5180. for_each_policy(policy) {
  5181. if (cpumask_test_cpu(cpu, policy->related_cpus)) {
  5182. read_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5183. ret = cpufreq_add_policy_cpu(policy, cpu, dev);
  5184. - up_read(&cpufreq_rwsem);
  5185. return ret;
  5186. }
  5187. }
  5188. @@ -1269,8 +1243,6 @@
  5189. kobject_uevent(&policy->kobj, KOBJ_ADD);
  5190. - up_read(&cpufreq_rwsem);
  5191. -
  5192. /* Callback for handling stuff after policy is ready */
  5193. if (cpufreq_driver->ready)
  5194. cpufreq_driver->ready(policy);
  5195. @@ -1304,8 +1276,6 @@
  5196. cpufreq_policy_free(policy);
  5197. nomem_out:
  5198. - up_read(&cpufreq_rwsem);
  5199. -
  5200. return ret;
  5201. }
  5202. @@ -2499,19 +2469,20 @@
  5203. pr_debug("unregistering driver %s\n", driver->name);
  5204. + /* Protect against concurrent cpu hotplug */
  5205. + get_online_cpus();
  5206. subsys_interface_unregister(&cpufreq_interface);
  5207. if (cpufreq_boost_supported())
  5208. cpufreq_sysfs_remove_file(&boost.attr);
  5209. unregister_hotcpu_notifier(&cpufreq_cpu_notifier);
  5210. - down_write(&cpufreq_rwsem);
  5211. write_lock_irqsave(&cpufreq_driver_lock, flags);
  5212. cpufreq_driver = NULL;
  5213. write_unlock_irqrestore(&cpufreq_driver_lock, flags);
  5214. - up_write(&cpufreq_rwsem);
  5215. + put_online_cpus();
  5216. return 0;
  5217. }
  5218. diff -Nur linux-4.1.6.orig/drivers/cpufreq/Kconfig.x86 linux-4.1.6/drivers/cpufreq/Kconfig.x86
  5219. --- linux-4.1.6.orig/drivers/cpufreq/Kconfig.x86 2015-08-17 05:52:51.000000000 +0200
  5220. +++ linux-4.1.6/drivers/cpufreq/Kconfig.x86 2015-09-08 23:49:05.818121077 +0200
  5221. @@ -123,7 +123,7 @@
  5222. config X86_POWERNOW_K8
  5223. tristate "AMD Opteron/Athlon64 PowerNow!"
  5224. - depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ
  5225. + depends on ACPI && ACPI_PROCESSOR && X86_ACPI_CPUFREQ && !PREEMPT_RT_BASE
  5226. help
  5227. This adds the CPUFreq driver for K8/early Opteron/Athlon64 processors.
  5228. Support for K10 and newer processors is now in acpi-cpufreq.
  5229. diff -Nur linux-4.1.6.orig/drivers/gpio/gpio-omap.c linux-4.1.6/drivers/gpio/gpio-omap.c
  5230. --- linux-4.1.6.orig/drivers/gpio/gpio-omap.c 2015-08-17 05:52:51.000000000 +0200
  5231. +++ linux-4.1.6/drivers/gpio/gpio-omap.c 2015-09-08 23:49:05.818121077 +0200
  5232. @@ -57,7 +57,7 @@
  5233. u32 saved_datain;
  5234. u32 level_mask;
  5235. u32 toggle_mask;
  5236. - spinlock_t lock;
  5237. + raw_spinlock_t lock;
  5238. struct gpio_chip chip;
  5239. struct clk *dbck;
  5240. u32 mod_usage;
  5241. @@ -498,14 +498,14 @@
  5242. (type & (IRQ_TYPE_LEVEL_LOW|IRQ_TYPE_LEVEL_HIGH)))
  5243. return -EINVAL;
  5244. - spin_lock_irqsave(&bank->lock, flags);
  5245. + raw_spin_lock_irqsave(&bank->lock, flags);
  5246. retval = omap_set_gpio_triggering(bank, offset, type);
  5247. omap_gpio_init_irq(bank, offset);
  5248. if (!omap_gpio_is_input(bank, offset)) {
  5249. - spin_unlock_irqrestore(&bank->lock, flags);
  5250. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5251. return -EINVAL;
  5252. }
  5253. - spin_unlock_irqrestore(&bank->lock, flags);
  5254. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5255. if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  5256. __irq_set_handler_locked(d->irq, handle_level_irq);
  5257. @@ -626,14 +626,14 @@
  5258. return -EINVAL;
  5259. }
  5260. - spin_lock_irqsave(&bank->lock, flags);
  5261. + raw_spin_lock_irqsave(&bank->lock, flags);
  5262. if (enable)
  5263. bank->context.wake_en |= gpio_bit;
  5264. else
  5265. bank->context.wake_en &= ~gpio_bit;
  5266. writel_relaxed(bank->context.wake_en, bank->base + bank->regs->wkup_en);
  5267. - spin_unlock_irqrestore(&bank->lock, flags);
  5268. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5269. return 0;
  5270. }
  5271. @@ -668,7 +668,7 @@
  5272. if (!BANK_USED(bank))
  5273. pm_runtime_get_sync(bank->dev);
  5274. - spin_lock_irqsave(&bank->lock, flags);
  5275. + raw_spin_lock_irqsave(&bank->lock, flags);
  5276. /* Set trigger to none. You need to enable the desired trigger with
  5277. * request_irq() or set_irq_type(). Only do this if the IRQ line has
  5278. * not already been requested.
  5279. @@ -678,7 +678,7 @@
  5280. omap_enable_gpio_module(bank, offset);
  5281. }
  5282. bank->mod_usage |= BIT(offset);
  5283. - spin_unlock_irqrestore(&bank->lock, flags);
  5284. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5285. return 0;
  5286. }
  5287. @@ -688,11 +688,11 @@
  5288. struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
  5289. unsigned long flags;
  5290. - spin_lock_irqsave(&bank->lock, flags);
  5291. + raw_spin_lock_irqsave(&bank->lock, flags);
  5292. bank->mod_usage &= ~(BIT(offset));
  5293. omap_disable_gpio_module(bank, offset);
  5294. omap_reset_gpio(bank, offset);
  5295. - spin_unlock_irqrestore(&bank->lock, flags);
  5296. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5297. /*
  5298. * If this is the last gpio to be freed in the bank,
  5299. @@ -794,9 +794,9 @@
  5300. if (!BANK_USED(bank))
  5301. pm_runtime_get_sync(bank->dev);
  5302. - spin_lock_irqsave(&bank->lock, flags);
  5303. + raw_spin_lock_irqsave(&bank->lock, flags);
  5304. omap_gpio_init_irq(bank, offset);
  5305. - spin_unlock_irqrestore(&bank->lock, flags);
  5306. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5307. omap_gpio_unmask_irq(d);
  5308. return 0;
  5309. @@ -808,11 +808,11 @@
  5310. unsigned long flags;
  5311. unsigned offset = d->hwirq;
  5312. - spin_lock_irqsave(&bank->lock, flags);
  5313. + raw_spin_lock_irqsave(&bank->lock, flags);
  5314. bank->irq_usage &= ~(BIT(offset));
  5315. omap_disable_gpio_module(bank, offset);
  5316. omap_reset_gpio(bank, offset);
  5317. - spin_unlock_irqrestore(&bank->lock, flags);
  5318. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5319. /*
  5320. * If this is the last IRQ to be freed in the bank,
  5321. @@ -836,10 +836,10 @@
  5322. unsigned offset = d->hwirq;
  5323. unsigned long flags;
  5324. - spin_lock_irqsave(&bank->lock, flags);
  5325. + raw_spin_lock_irqsave(&bank->lock, flags);
  5326. omap_set_gpio_irqenable(bank, offset, 0);
  5327. omap_set_gpio_triggering(bank, offset, IRQ_TYPE_NONE);
  5328. - spin_unlock_irqrestore(&bank->lock, flags);
  5329. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5330. }
  5331. static void omap_gpio_unmask_irq(struct irq_data *d)
  5332. @@ -849,7 +849,7 @@
  5333. u32 trigger = irqd_get_trigger_type(d);
  5334. unsigned long flags;
  5335. - spin_lock_irqsave(&bank->lock, flags);
  5336. + raw_spin_lock_irqsave(&bank->lock, flags);
  5337. if (trigger)
  5338. omap_set_gpio_triggering(bank, offset, trigger);
  5339. @@ -861,7 +861,7 @@
  5340. }
  5341. omap_set_gpio_irqenable(bank, offset, 1);
  5342. - spin_unlock_irqrestore(&bank->lock, flags);
  5343. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5344. }
  5345. /*---------------------------------------------------------------------*/
  5346. @@ -874,9 +874,9 @@
  5347. OMAP_MPUIO_GPIO_MASKIT / bank->stride;
  5348. unsigned long flags;
  5349. - spin_lock_irqsave(&bank->lock, flags);
  5350. + raw_spin_lock_irqsave(&bank->lock, flags);
  5351. writel_relaxed(0xffff & ~bank->context.wake_en, mask_reg);
  5352. - spin_unlock_irqrestore(&bank->lock, flags);
  5353. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5354. return 0;
  5355. }
  5356. @@ -889,9 +889,9 @@
  5357. OMAP_MPUIO_GPIO_MASKIT / bank->stride;
  5358. unsigned long flags;
  5359. - spin_lock_irqsave(&bank->lock, flags);
  5360. + raw_spin_lock_irqsave(&bank->lock, flags);
  5361. writel_relaxed(bank->context.wake_en, mask_reg);
  5362. - spin_unlock_irqrestore(&bank->lock, flags);
  5363. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5364. return 0;
  5365. }
  5366. @@ -937,9 +937,9 @@
  5367. bank = container_of(chip, struct gpio_bank, chip);
  5368. reg = bank->base + bank->regs->direction;
  5369. - spin_lock_irqsave(&bank->lock, flags);
  5370. + raw_spin_lock_irqsave(&bank->lock, flags);
  5371. dir = !!(readl_relaxed(reg) & BIT(offset));
  5372. - spin_unlock_irqrestore(&bank->lock, flags);
  5373. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5374. return dir;
  5375. }
  5376. @@ -949,9 +949,9 @@
  5377. unsigned long flags;
  5378. bank = container_of(chip, struct gpio_bank, chip);
  5379. - spin_lock_irqsave(&bank->lock, flags);
  5380. + raw_spin_lock_irqsave(&bank->lock, flags);
  5381. omap_set_gpio_direction(bank, offset, 1);
  5382. - spin_unlock_irqrestore(&bank->lock, flags);
  5383. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5384. return 0;
  5385. }
  5386. @@ -973,10 +973,10 @@
  5387. unsigned long flags;
  5388. bank = container_of(chip, struct gpio_bank, chip);
  5389. - spin_lock_irqsave(&bank->lock, flags);
  5390. + raw_spin_lock_irqsave(&bank->lock, flags);
  5391. bank->set_dataout(bank, offset, value);
  5392. omap_set_gpio_direction(bank, offset, 0);
  5393. - spin_unlock_irqrestore(&bank->lock, flags);
  5394. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5395. return 0;
  5396. }
  5397. @@ -988,9 +988,9 @@
  5398. bank = container_of(chip, struct gpio_bank, chip);
  5399. - spin_lock_irqsave(&bank->lock, flags);
  5400. + raw_spin_lock_irqsave(&bank->lock, flags);
  5401. omap2_set_gpio_debounce(bank, offset, debounce);
  5402. - spin_unlock_irqrestore(&bank->lock, flags);
  5403. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5404. return 0;
  5405. }
  5406. @@ -1001,9 +1001,9 @@
  5407. unsigned long flags;
  5408. bank = container_of(chip, struct gpio_bank, chip);
  5409. - spin_lock_irqsave(&bank->lock, flags);
  5410. + raw_spin_lock_irqsave(&bank->lock, flags);
  5411. bank->set_dataout(bank, offset, value);
  5412. - spin_unlock_irqrestore(&bank->lock, flags);
  5413. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5414. }
  5415. /*---------------------------------------------------------------------*/
  5416. @@ -1199,7 +1199,7 @@
  5417. else
  5418. bank->set_dataout = omap_set_gpio_dataout_mask;
  5419. - spin_lock_init(&bank->lock);
  5420. + raw_spin_lock_init(&bank->lock);
  5421. /* Static mapping, never released */
  5422. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  5423. @@ -1246,7 +1246,7 @@
  5424. unsigned long flags;
  5425. u32 wake_low, wake_hi;
  5426. - spin_lock_irqsave(&bank->lock, flags);
  5427. + raw_spin_lock_irqsave(&bank->lock, flags);
  5428. /*
  5429. * Only edges can generate a wakeup event to the PRCM.
  5430. @@ -1299,7 +1299,7 @@
  5431. bank->get_context_loss_count(bank->dev);
  5432. omap_gpio_dbck_disable(bank);
  5433. - spin_unlock_irqrestore(&bank->lock, flags);
  5434. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5435. return 0;
  5436. }
  5437. @@ -1314,7 +1314,7 @@
  5438. unsigned long flags;
  5439. int c;
  5440. - spin_lock_irqsave(&bank->lock, flags);
  5441. + raw_spin_lock_irqsave(&bank->lock, flags);
  5442. /*
  5443. * On the first resume during the probe, the context has not
  5444. @@ -1350,14 +1350,14 @@
  5445. if (c != bank->context_loss_count) {
  5446. omap_gpio_restore_context(bank);
  5447. } else {
  5448. - spin_unlock_irqrestore(&bank->lock, flags);
  5449. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5450. return 0;
  5451. }
  5452. }
  5453. }
  5454. if (!bank->workaround_enabled) {
  5455. - spin_unlock_irqrestore(&bank->lock, flags);
  5456. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5457. return 0;
  5458. }
  5459. @@ -1412,7 +1412,7 @@
  5460. }
  5461. bank->workaround_enabled = false;
  5462. - spin_unlock_irqrestore(&bank->lock, flags);
  5463. + raw_spin_unlock_irqrestore(&bank->lock, flags);
  5464. return 0;
  5465. }
  5466. diff -Nur linux-4.1.6.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c linux-4.1.6/drivers/gpu/drm/i915/i915_gem_execbuffer.c
  5467. --- linux-4.1.6.orig/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2015-08-17 05:52:51.000000000 +0200
  5468. +++ linux-4.1.6/drivers/gpu/drm/i915/i915_gem_execbuffer.c 2015-09-08 23:49:05.818121077 +0200
  5469. @@ -32,6 +32,7 @@
  5470. #include "i915_trace.h"
  5471. #include "intel_drv.h"
  5472. #include <linux/dma_remapping.h>
  5473. +#include <linux/uaccess.h>
  5474. #define __EXEC_OBJECT_HAS_PIN (1<<31)
  5475. #define __EXEC_OBJECT_HAS_FENCE (1<<30)
  5476. @@ -465,7 +466,7 @@
  5477. }
  5478. /* We can't wait for rendering with pagefaults disabled */
  5479. - if (obj->active && in_atomic())
  5480. + if (obj->active && pagefault_disabled())
  5481. return -EFAULT;
  5482. if (use_cpu_reloc(obj))
  5483. @@ -1338,7 +1339,9 @@
  5484. return ret;
  5485. }
  5486. +#ifndef CONFIG_PREEMPT_RT_BASE
  5487. trace_i915_gem_ring_dispatch(intel_ring_get_request(ring), dispatch_flags);
  5488. +#endif
  5489. i915_gem_execbuffer_move_to_active(vmas, ring);
  5490. i915_gem_execbuffer_retire_commands(dev, file, ring, batch_obj);
  5491. diff -Nur linux-4.1.6.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c linux-4.1.6/drivers/gpu/drm/i915/i915_gem_shrinker.c
  5492. --- linux-4.1.6.orig/drivers/gpu/drm/i915/i915_gem_shrinker.c 2015-08-17 05:52:51.000000000 +0200
  5493. +++ linux-4.1.6/drivers/gpu/drm/i915/i915_gem_shrinker.c 2015-09-08 23:49:05.818121077 +0200
  5494. @@ -39,7 +39,7 @@
  5495. if (!mutex_is_locked(mutex))
  5496. return false;
  5497. -#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)
  5498. +#if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_MUTEXES)) && !defined(CONFIG_PREEMPT_RT_BASE)
  5499. return mutex->owner == task;
  5500. #else
  5501. /* Since UP may be pre-empted, we cannot assume that we own the lock */
  5502. diff -Nur linux-4.1.6.orig/drivers/gpu/drm/i915/intel_display.c linux-4.1.6/drivers/gpu/drm/i915/intel_display.c
  5503. --- linux-4.1.6.orig/drivers/gpu/drm/i915/intel_display.c 2015-08-17 05:52:51.000000000 +0200
  5504. +++ linux-4.1.6/drivers/gpu/drm/i915/intel_display.c 2015-09-08 23:49:05.822120634 +0200
  5505. @@ -10086,7 +10086,7 @@
  5506. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5507. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5508. - WARN_ON(!in_interrupt());
  5509. + WARN_ON_NONRT(!in_interrupt());
  5510. if (crtc == NULL)
  5511. return;
  5512. diff -Nur linux-4.1.6.orig/drivers/i2c/busses/i2c-omap.c linux-4.1.6/drivers/i2c/busses/i2c-omap.c
  5513. --- linux-4.1.6.orig/drivers/i2c/busses/i2c-omap.c 2015-08-17 05:52:51.000000000 +0200
  5514. +++ linux-4.1.6/drivers/i2c/busses/i2c-omap.c 2015-09-08 23:49:06.074092692 +0200
  5515. @@ -996,15 +996,12 @@
  5516. u16 mask;
  5517. u16 stat;
  5518. - spin_lock(&dev->lock);
  5519. - mask = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
  5520. stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
  5521. + mask = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
  5522. if (stat & mask)
  5523. ret = IRQ_WAKE_THREAD;
  5524. - spin_unlock(&dev->lock);
  5525. -
  5526. return ret;
  5527. }
  5528. diff -Nur linux-4.1.6.orig/drivers/ide/alim15x3.c linux-4.1.6/drivers/ide/alim15x3.c
  5529. --- linux-4.1.6.orig/drivers/ide/alim15x3.c 2015-08-17 05:52:51.000000000 +0200
  5530. +++ linux-4.1.6/drivers/ide/alim15x3.c 2015-09-08 23:49:06.074092692 +0200
  5531. @@ -234,7 +234,7 @@
  5532. isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
  5533. - local_irq_save(flags);
  5534. + local_irq_save_nort(flags);
  5535. if (m5229_revision < 0xC2) {
  5536. /*
  5537. @@ -325,7 +325,7 @@
  5538. }
  5539. pci_dev_put(north);
  5540. pci_dev_put(isa_dev);
  5541. - local_irq_restore(flags);
  5542. + local_irq_restore_nort(flags);
  5543. return 0;
  5544. }
  5545. diff -Nur linux-4.1.6.orig/drivers/ide/hpt366.c linux-4.1.6/drivers/ide/hpt366.c
  5546. --- linux-4.1.6.orig/drivers/ide/hpt366.c 2015-08-17 05:52:51.000000000 +0200
  5547. +++ linux-4.1.6/drivers/ide/hpt366.c 2015-09-08 23:49:06.074092692 +0200
  5548. @@ -1241,7 +1241,7 @@
  5549. dma_old = inb(base + 2);
  5550. - local_irq_save(flags);
  5551. + local_irq_save_nort(flags);
  5552. dma_new = dma_old;
  5553. pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
  5554. @@ -1252,7 +1252,7 @@
  5555. if (dma_new != dma_old)
  5556. outb(dma_new, base + 2);
  5557. - local_irq_restore(flags);
  5558. + local_irq_restore_nort(flags);
  5559. printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx\n",
  5560. hwif->name, base, base + 7);
  5561. diff -Nur linux-4.1.6.orig/drivers/ide/ide-io.c linux-4.1.6/drivers/ide/ide-io.c
  5562. --- linux-4.1.6.orig/drivers/ide/ide-io.c 2015-08-17 05:52:51.000000000 +0200
  5563. +++ linux-4.1.6/drivers/ide/ide-io.c 2015-09-08 23:49:06.074092692 +0200
  5564. @@ -659,7 +659,7 @@
  5565. /* disable_irq_nosync ?? */
  5566. disable_irq(hwif->irq);
  5567. /* local CPU only, as if we were handling an interrupt */
  5568. - local_irq_disable();
  5569. + local_irq_disable_nort();
  5570. if (hwif->polling) {
  5571. startstop = handler(drive);
  5572. } else if (drive_is_ready(drive)) {
  5573. diff -Nur linux-4.1.6.orig/drivers/ide/ide-iops.c linux-4.1.6/drivers/ide/ide-iops.c
  5574. --- linux-4.1.6.orig/drivers/ide/ide-iops.c 2015-08-17 05:52:51.000000000 +0200
  5575. +++ linux-4.1.6/drivers/ide/ide-iops.c 2015-09-08 23:49:06.074092692 +0200
  5576. @@ -129,12 +129,12 @@
  5577. if ((stat & ATA_BUSY) == 0)
  5578. break;
  5579. - local_irq_restore(flags);
  5580. + local_irq_restore_nort(flags);
  5581. *rstat = stat;
  5582. return -EBUSY;
  5583. }
  5584. }
  5585. - local_irq_restore(flags);
  5586. + local_irq_restore_nort(flags);
  5587. }
  5588. /*
  5589. * Allow status to settle, then read it again.
  5590. diff -Nur linux-4.1.6.orig/drivers/ide/ide-io-std.c linux-4.1.6/drivers/ide/ide-io-std.c
  5591. --- linux-4.1.6.orig/drivers/ide/ide-io-std.c 2015-08-17 05:52:51.000000000 +0200
  5592. +++ linux-4.1.6/drivers/ide/ide-io-std.c 2015-09-08 23:49:06.074092692 +0200
  5593. @@ -175,7 +175,7 @@
  5594. unsigned long uninitialized_var(flags);
  5595. if ((io_32bit & 2) && !mmio) {
  5596. - local_irq_save(flags);
  5597. + local_irq_save_nort(flags);
  5598. ata_vlb_sync(io_ports->nsect_addr);
  5599. }
  5600. @@ -186,7 +186,7 @@
  5601. insl(data_addr, buf, words);
  5602. if ((io_32bit & 2) && !mmio)
  5603. - local_irq_restore(flags);
  5604. + local_irq_restore_nort(flags);
  5605. if (((len + 1) & 3) < 2)
  5606. return;
  5607. @@ -219,7 +219,7 @@
  5608. unsigned long uninitialized_var(flags);
  5609. if ((io_32bit & 2) && !mmio) {
  5610. - local_irq_save(flags);
  5611. + local_irq_save_nort(flags);
  5612. ata_vlb_sync(io_ports->nsect_addr);
  5613. }
  5614. @@ -230,7 +230,7 @@
  5615. outsl(data_addr, buf, words);
  5616. if ((io_32bit & 2) && !mmio)
  5617. - local_irq_restore(flags);
  5618. + local_irq_restore_nort(flags);
  5619. if (((len + 1) & 3) < 2)
  5620. return;
  5621. diff -Nur linux-4.1.6.orig/drivers/ide/ide-probe.c linux-4.1.6/drivers/ide/ide-probe.c
  5622. --- linux-4.1.6.orig/drivers/ide/ide-probe.c 2015-08-17 05:52:51.000000000 +0200
  5623. +++ linux-4.1.6/drivers/ide/ide-probe.c 2015-09-08 23:49:06.074092692 +0200
  5624. @@ -196,10 +196,10 @@
  5625. int bswap = 1;
  5626. /* local CPU only; some systems need this */
  5627. - local_irq_save(flags);
  5628. + local_irq_save_nort(flags);
  5629. /* read 512 bytes of id info */
  5630. hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
  5631. - local_irq_restore(flags);
  5632. + local_irq_restore_nort(flags);
  5633. drive->dev_flags |= IDE_DFLAG_ID_READ;
  5634. #ifdef DEBUG
  5635. diff -Nur linux-4.1.6.orig/drivers/ide/ide-taskfile.c linux-4.1.6/drivers/ide/ide-taskfile.c
  5636. --- linux-4.1.6.orig/drivers/ide/ide-taskfile.c 2015-08-17 05:52:51.000000000 +0200
  5637. +++ linux-4.1.6/drivers/ide/ide-taskfile.c 2015-09-08 23:49:06.074092692 +0200
  5638. @@ -250,7 +250,7 @@
  5639. page_is_high = PageHighMem(page);
  5640. if (page_is_high)
  5641. - local_irq_save(flags);
  5642. + local_irq_save_nort(flags);
  5643. buf = kmap_atomic(page) + offset;
  5644. @@ -271,7 +271,7 @@
  5645. kunmap_atomic(buf);
  5646. if (page_is_high)
  5647. - local_irq_restore(flags);
  5648. + local_irq_restore_nort(flags);
  5649. len -= nr_bytes;
  5650. }
  5651. @@ -414,7 +414,7 @@
  5652. }
  5653. if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
  5654. - local_irq_disable();
  5655. + local_irq_disable_nort();
  5656. ide_set_handler(drive, &task_pio_intr, WAIT_WORSTCASE);
  5657. diff -Nur linux-4.1.6.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c linux-4.1.6/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
  5658. --- linux-4.1.6.orig/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-08-17 05:52:51.000000000 +0200
  5659. +++ linux-4.1.6/drivers/infiniband/ulp/ipoib/ipoib_multicast.c 2015-09-08 23:49:06.074092692 +0200
  5660. @@ -821,7 +821,7 @@
  5661. ipoib_dbg_mcast(priv, "restarting multicast task\n");
  5662. - local_irq_save(flags);
  5663. + local_irq_save_nort(flags);
  5664. netif_addr_lock(dev);
  5665. spin_lock(&priv->lock);
  5666. @@ -903,7 +903,7 @@
  5667. spin_unlock(&priv->lock);
  5668. netif_addr_unlock(dev);
  5669. - local_irq_restore(flags);
  5670. + local_irq_restore_nort(flags);
  5671. /*
  5672. * make sure the in-flight joins have finished before we attempt
  5673. diff -Nur linux-4.1.6.orig/drivers/input/gameport/gameport.c linux-4.1.6/drivers/input/gameport/gameport.c
  5674. --- linux-4.1.6.orig/drivers/input/gameport/gameport.c 2015-08-17 05:52:51.000000000 +0200
  5675. +++ linux-4.1.6/drivers/input/gameport/gameport.c 2015-09-08 23:49:06.074092692 +0200
  5676. @@ -124,12 +124,12 @@
  5677. tx = 1 << 30;
  5678. for(i = 0; i < 50; i++) {
  5679. - local_irq_save(flags);
  5680. + local_irq_save_nort(flags);
  5681. GET_TIME(t1);
  5682. for (t = 0; t < 50; t++) gameport_read(gameport);
  5683. GET_TIME(t2);
  5684. GET_TIME(t3);
  5685. - local_irq_restore(flags);
  5686. + local_irq_restore_nort(flags);
  5687. udelay(i * 10);
  5688. if ((t = DELTA(t2,t1) - DELTA(t3,t2)) < tx) tx = t;
  5689. }
  5690. @@ -148,11 +148,11 @@
  5691. tx = 1 << 30;
  5692. for(i = 0; i < 50; i++) {
  5693. - local_irq_save(flags);
  5694. + local_irq_save_nort(flags);
  5695. rdtscl(t1);
  5696. for (t = 0; t < 50; t++) gameport_read(gameport);
  5697. rdtscl(t2);
  5698. - local_irq_restore(flags);
  5699. + local_irq_restore_nort(flags);
  5700. udelay(i * 10);
  5701. if (t2 - t1 < tx) tx = t2 - t1;
  5702. }
  5703. diff -Nur linux-4.1.6.orig/drivers/leds/trigger/Kconfig linux-4.1.6/drivers/leds/trigger/Kconfig
  5704. --- linux-4.1.6.orig/drivers/leds/trigger/Kconfig 2015-08-17 05:52:51.000000000 +0200
  5705. +++ linux-4.1.6/drivers/leds/trigger/Kconfig 2015-09-08 23:49:06.074092692 +0200
  5706. @@ -61,7 +61,7 @@
  5707. config LEDS_TRIGGER_CPU
  5708. bool "LED CPU Trigger"
  5709. - depends on LEDS_TRIGGERS
  5710. + depends on LEDS_TRIGGERS && !PREEMPT_RT_BASE
  5711. help
  5712. This allows LEDs to be controlled by active CPUs. This shows
  5713. the active CPUs across an array of LEDs so you can see which
  5714. diff -Nur linux-4.1.6.orig/drivers/md/bcache/Kconfig linux-4.1.6/drivers/md/bcache/Kconfig
  5715. --- linux-4.1.6.orig/drivers/md/bcache/Kconfig 2015-08-17 05:52:51.000000000 +0200
  5716. +++ linux-4.1.6/drivers/md/bcache/Kconfig 2015-09-08 23:49:06.074092692 +0200
  5717. @@ -1,6 +1,7 @@
  5718. config BCACHE
  5719. tristate "Block device as cache"
  5720. + depends on !PREEMPT_RT_FULL
  5721. ---help---
  5722. Allows a block device to be used as cache for other devices; uses
  5723. a btree for indexing and the layout is optimized for SSDs.
  5724. diff -Nur linux-4.1.6.orig/drivers/md/dm.c linux-4.1.6/drivers/md/dm.c
  5725. --- linux-4.1.6.orig/drivers/md/dm.c 2015-08-17 05:52:51.000000000 +0200
  5726. +++ linux-4.1.6/drivers/md/dm.c 2015-09-08 23:49:06.074092692 +0200
  5727. @@ -2132,7 +2132,7 @@
  5728. /* Establish tio->ti before queuing work (map_tio_request) */
  5729. tio->ti = ti;
  5730. queue_kthread_work(&md->kworker, &tio->work);
  5731. - BUG_ON(!irqs_disabled());
  5732. + BUG_ON_NONRT(!irqs_disabled());
  5733. }
  5734. goto out;
  5735. diff -Nur linux-4.1.6.orig/drivers/md/raid5.c linux-4.1.6/drivers/md/raid5.c
  5736. --- linux-4.1.6.orig/drivers/md/raid5.c 2015-08-17 05:52:51.000000000 +0200
  5737. +++ linux-4.1.6/drivers/md/raid5.c 2015-09-08 23:49:06.078092247 +0200
  5738. @@ -1918,8 +1918,9 @@
  5739. struct raid5_percpu *percpu;
  5740. unsigned long cpu;
  5741. - cpu = get_cpu();
  5742. + cpu = get_cpu_light();
  5743. percpu = per_cpu_ptr(conf->percpu, cpu);
  5744. + spin_lock(&percpu->lock);
  5745. if (test_bit(STRIPE_OP_BIOFILL, &ops_request)) {
  5746. ops_run_biofill(sh);
  5747. overlap_clear++;
  5748. @@ -1975,7 +1976,8 @@
  5749. if (test_and_clear_bit(R5_Overlap, &dev->flags))
  5750. wake_up(&sh->raid_conf->wait_for_overlap);
  5751. }
  5752. - put_cpu();
  5753. + spin_unlock(&percpu->lock);
  5754. + put_cpu_light();
  5755. }
  5756. static struct stripe_head *alloc_stripe(struct kmem_cache *sc, gfp_t gfp)
  5757. @@ -6350,6 +6352,7 @@
  5758. __func__, cpu);
  5759. break;
  5760. }
  5761. + spin_lock_init(&per_cpu_ptr(conf->percpu, cpu)->lock);
  5762. }
  5763. put_online_cpus();
  5764. diff -Nur linux-4.1.6.orig/drivers/md/raid5.h linux-4.1.6/drivers/md/raid5.h
  5765. --- linux-4.1.6.orig/drivers/md/raid5.h 2015-08-17 05:52:51.000000000 +0200
  5766. +++ linux-4.1.6/drivers/md/raid5.h 2015-09-08 23:49:06.078092247 +0200
  5767. @@ -494,6 +494,7 @@
  5768. int recovery_disabled;
  5769. /* per cpu variables */
  5770. struct raid5_percpu {
  5771. + spinlock_t lock; /* Protection for -RT */
  5772. struct page *spare_page; /* Used when checking P/Q in raid6 */
  5773. struct flex_array *scribble; /* space for constructing buffer
  5774. * lists and performing address
  5775. diff -Nur linux-4.1.6.orig/drivers/misc/hwlat_detector.c linux-4.1.6/drivers/misc/hwlat_detector.c
  5776. --- linux-4.1.6.orig/drivers/misc/hwlat_detector.c 1970-01-01 01:00:00.000000000 +0100
  5777. +++ linux-4.1.6/drivers/misc/hwlat_detector.c 2015-09-08 23:49:06.082091803 +0200
  5778. @@ -0,0 +1,1240 @@
  5779. +/*
  5780. + * hwlat_detector.c - A simple Hardware Latency detector.
  5781. + *
  5782. + * Use this module to detect large system latencies induced by the behavior of
  5783. + * certain underlying system hardware or firmware, independent of Linux itself.
  5784. + * The code was developed originally to detect the presence of SMIs on Intel
  5785. + * and AMD systems, although there is no dependency upon x86 herein.
  5786. + *
  5787. + * The classical example usage of this module is in detecting the presence of
  5788. + * SMIs or System Management Interrupts on Intel and AMD systems. An SMI is a
  5789. + * somewhat special form of hardware interrupt spawned from earlier CPU debug
  5790. + * modes in which the (BIOS/EFI/etc.) firmware arranges for the South Bridge
  5791. + * LPC (or other device) to generate a special interrupt under certain
  5792. + * circumstances, for example, upon expiration of a special SMI timer device,
  5793. + * due to certain external thermal readings, on certain I/O address accesses,
  5794. + * and other situations. An SMI hits a special CPU pin, triggers a special
  5795. + * SMI mode (complete with special memory map), and the OS is unaware.
  5796. + *
  5797. + * Although certain hardware-inducing latencies are necessary (for example,
  5798. + * a modern system often requires an SMI handler for correct thermal control
  5799. + * and remote management) they can wreak havoc upon any OS-level performance
  5800. + * guarantees toward low-latency, especially when the OS is not even made
  5801. + * aware of the presence of these interrupts. For this reason, we need a
  5802. + * somewhat brute force mechanism to detect these interrupts. In this case,
  5803. + * we do it by hogging all of the CPU(s) for configurable timer intervals,
  5804. + * sampling the built-in CPU timer, looking for discontiguous readings.
  5805. + *
  5806. + * WARNING: This implementation necessarily introduces latencies. Therefore,
  5807. + * you should NEVER use this module in a production environment
  5808. + * requiring any kind of low-latency performance guarantee(s).
  5809. + *
  5810. + * Copyright (C) 2008-2009 Jon Masters, Red Hat, Inc. <jcm@redhat.com>
  5811. + *
  5812. + * Includes useful feedback from Clark Williams <clark@redhat.com>
  5813. + *
  5814. + * This file is licensed under the terms of the GNU General Public
  5815. + * License version 2. This program is licensed "as is" without any
  5816. + * warranty of any kind, whether express or implied.
  5817. + */
  5818. +
  5819. +#include <linux/module.h>
  5820. +#include <linux/init.h>
  5821. +#include <linux/ring_buffer.h>
  5822. +#include <linux/time.h>
  5823. +#include <linux/hrtimer.h>
  5824. +#include <linux/kthread.h>
  5825. +#include <linux/debugfs.h>
  5826. +#include <linux/seq_file.h>
  5827. +#include <linux/uaccess.h>
  5828. +#include <linux/version.h>
  5829. +#include <linux/delay.h>
  5830. +#include <linux/slab.h>
  5831. +#include <linux/trace_clock.h>
  5832. +
  5833. +#define BUF_SIZE_DEFAULT 262144UL /* 8K*(sizeof(entry)) */
  5834. +#define BUF_FLAGS (RB_FL_OVERWRITE) /* no block on full */
  5835. +#define U64STR_SIZE 22 /* 20 digits max */
  5836. +
  5837. +#define VERSION "1.0.0"
  5838. +#define BANNER "hwlat_detector: "
  5839. +#define DRVNAME "hwlat_detector"
  5840. +#define DEFAULT_SAMPLE_WINDOW 1000000 /* 1s */
  5841. +#define DEFAULT_SAMPLE_WIDTH 500000 /* 0.5s */
  5842. +#define DEFAULT_LAT_THRESHOLD 10 /* 10us */
  5843. +
  5844. +/* Module metadata */
  5845. +
  5846. +MODULE_LICENSE("GPL");
  5847. +MODULE_AUTHOR("Jon Masters <jcm@redhat.com>");
  5848. +MODULE_DESCRIPTION("A simple hardware latency detector");
  5849. +MODULE_VERSION(VERSION);
  5850. +
  5851. +/* Module parameters */
  5852. +
  5853. +static int debug;
  5854. +static int enabled;
  5855. +static int threshold;
  5856. +
  5857. +module_param(debug, int, 0); /* enable debug */
  5858. +module_param(enabled, int, 0); /* enable detector */
  5859. +module_param(threshold, int, 0); /* latency threshold */
  5860. +
  5861. +/* Buffering and sampling */
  5862. +
  5863. +static struct ring_buffer *ring_buffer; /* sample buffer */
  5864. +static DEFINE_MUTEX(ring_buffer_mutex); /* lock changes */
  5865. +static unsigned long buf_size = BUF_SIZE_DEFAULT;
  5866. +static struct task_struct *kthread; /* sampling thread */
  5867. +
  5868. +/* DebugFS filesystem entries */
  5869. +
  5870. +static struct dentry *debug_dir; /* debugfs directory */
  5871. +static struct dentry *debug_max; /* maximum TSC delta */
  5872. +static struct dentry *debug_count; /* total detect count */
  5873. +static struct dentry *debug_sample_width; /* sample width us */
  5874. +static struct dentry *debug_sample_window; /* sample window us */
  5875. +static struct dentry *debug_sample; /* raw samples us */
  5876. +static struct dentry *debug_threshold; /* threshold us */
  5877. +static struct dentry *debug_enable; /* enable/disable */
  5878. +
  5879. +/* Individual samples and global state */
  5880. +
  5881. +struct sample; /* latency sample */
  5882. +struct data; /* Global state */
  5883. +
  5884. +/* Sampling functions */
  5885. +static int __buffer_add_sample(struct sample *sample);
  5886. +static struct sample *buffer_get_sample(struct sample *sample);
  5887. +
  5888. +/* Threading and state */
  5889. +static int kthread_fn(void *unused);
  5890. +static int start_kthread(void);
  5891. +static int stop_kthread(void);
  5892. +static void __reset_stats(void);
  5893. +static int init_stats(void);
  5894. +
  5895. +/* Debugfs interface */
  5896. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  5897. + size_t cnt, loff_t *ppos, const u64 *entry);
  5898. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  5899. + size_t cnt, loff_t *ppos, u64 *entry);
  5900. +static int debug_sample_fopen(struct inode *inode, struct file *filp);
  5901. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  5902. + size_t cnt, loff_t *ppos);
  5903. +static int debug_sample_release(struct inode *inode, struct file *filp);
  5904. +static int debug_enable_fopen(struct inode *inode, struct file *filp);
  5905. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  5906. + size_t cnt, loff_t *ppos);
  5907. +static ssize_t debug_enable_fwrite(struct file *file,
  5908. + const char __user *user_buffer,
  5909. + size_t user_size, loff_t *offset);
  5910. +
  5911. +/* Initialization functions */
  5912. +static int init_debugfs(void);
  5913. +static void free_debugfs(void);
  5914. +static int detector_init(void);
  5915. +static void detector_exit(void);
  5916. +
  5917. +/* Individual latency samples are stored here when detected and packed into
  5918. + * the ring_buffer circular buffer, where they are overwritten when
  5919. + * more than buf_size/sizeof(sample) samples are received. */
  5920. +struct sample {
  5921. + u64 seqnum; /* unique sequence */
  5922. + u64 duration; /* ktime delta */
  5923. + u64 outer_duration; /* ktime delta (outer loop) */
  5924. + struct timespec timestamp; /* wall time */
  5925. + unsigned long lost;
  5926. +};
  5927. +
  5928. +/* keep the global state somewhere. */
  5929. +static struct data {
  5930. +
  5931. + struct mutex lock; /* protect changes */
  5932. +
  5933. + u64 count; /* total since reset */
  5934. + u64 max_sample; /* max hardware latency */
  5935. + u64 threshold; /* sample threshold level */
  5936. +
  5937. + u64 sample_window; /* total sampling window (on+off) */
  5938. + u64 sample_width; /* active sampling portion of window */
  5939. +
  5940. + atomic_t sample_open; /* whether the sample file is open */
  5941. +
  5942. + wait_queue_head_t wq; /* waitqeue for new sample values */
  5943. +
  5944. +} data;
  5945. +
  5946. +/**
  5947. + * __buffer_add_sample - add a new latency sample recording to the ring buffer
  5948. + * @sample: The new latency sample value
  5949. + *
  5950. + * This receives a new latency sample and records it in a global ring buffer.
  5951. + * No additional locking is used in this case.
  5952. + */
  5953. +static int __buffer_add_sample(struct sample *sample)
  5954. +{
  5955. + return ring_buffer_write(ring_buffer,
  5956. + sizeof(struct sample), sample);
  5957. +}
  5958. +
  5959. +/**
  5960. + * buffer_get_sample - remove a hardware latency sample from the ring buffer
  5961. + * @sample: Pre-allocated storage for the sample
  5962. + *
  5963. + * This retrieves a hardware latency sample from the global circular buffer
  5964. + */
  5965. +static struct sample *buffer_get_sample(struct sample *sample)
  5966. +{
  5967. + struct ring_buffer_event *e = NULL;
  5968. + struct sample *s = NULL;
  5969. + unsigned int cpu = 0;
  5970. +
  5971. + if (!sample)
  5972. + return NULL;
  5973. +
  5974. + mutex_lock(&ring_buffer_mutex);
  5975. + for_each_online_cpu(cpu) {
  5976. + e = ring_buffer_consume(ring_buffer, cpu, NULL, &sample->lost);
  5977. + if (e)
  5978. + break;
  5979. + }
  5980. +
  5981. + if (e) {
  5982. + s = ring_buffer_event_data(e);
  5983. + memcpy(sample, s, sizeof(struct sample));
  5984. + } else
  5985. + sample = NULL;
  5986. + mutex_unlock(&ring_buffer_mutex);
  5987. +
  5988. + return sample;
  5989. +}
  5990. +
  5991. +#ifndef CONFIG_TRACING
  5992. +#define time_type ktime_t
  5993. +#define time_get() ktime_get()
  5994. +#define time_to_us(x) ktime_to_us(x)
  5995. +#define time_sub(a, b) ktime_sub(a, b)
  5996. +#define init_time(a, b) (a).tv64 = b
  5997. +#define time_u64(a) ((a).tv64)
  5998. +#else
  5999. +#define time_type u64
  6000. +#define time_get() trace_clock_local()
  6001. +#define time_to_us(x) div_u64(x, 1000)
  6002. +#define time_sub(a, b) ((a) - (b))
  6003. +#define init_time(a, b) (a = b)
  6004. +#define time_u64(a) a
  6005. +#endif
  6006. +/**
  6007. + * get_sample - sample the CPU TSC and look for likely hardware latencies
  6008. + *
  6009. + * Used to repeatedly capture the CPU TSC (or similar), looking for potential
  6010. + * hardware-induced latency. Called with interrupts disabled and with
  6011. + * data.lock held.
  6012. + */
  6013. +static int get_sample(void)
  6014. +{
  6015. + time_type start, t1, t2, last_t2;
  6016. + s64 diff, total = 0;
  6017. + u64 sample = 0;
  6018. + u64 outer_sample = 0;
  6019. + int ret = -1;
  6020. +
  6021. + init_time(last_t2, 0);
  6022. + start = time_get(); /* start timestamp */
  6023. +
  6024. + do {
  6025. +
  6026. + t1 = time_get(); /* we'll look for a discontinuity */
  6027. + t2 = time_get();
  6028. +
  6029. + if (time_u64(last_t2)) {
  6030. + /* Check the delta from outer loop (t2 to next t1) */
  6031. + diff = time_to_us(time_sub(t1, last_t2));
  6032. + /* This shouldn't happen */
  6033. + if (diff < 0) {
  6034. + pr_err(BANNER "time running backwards\n");
  6035. + goto out;
  6036. + }
  6037. + if (diff > outer_sample)
  6038. + outer_sample = diff;
  6039. + }
  6040. + last_t2 = t2;
  6041. +
  6042. + total = time_to_us(time_sub(t2, start)); /* sample width */
  6043. +
  6044. + /* This checks the inner loop (t1 to t2) */
  6045. + diff = time_to_us(time_sub(t2, t1)); /* current diff */
  6046. +
  6047. + /* This shouldn't happen */
  6048. + if (diff < 0) {
  6049. + pr_err(BANNER "time running backwards\n");
  6050. + goto out;
  6051. + }
  6052. +
  6053. + if (diff > sample)
  6054. + sample = diff; /* only want highest value */
  6055. +
  6056. + } while (total <= data.sample_width);
  6057. +
  6058. + ret = 0;
  6059. +
  6060. + /* If we exceed the threshold value, we have found a hardware latency */
  6061. + if (sample > data.threshold || outer_sample > data.threshold) {
  6062. + struct sample s;
  6063. +
  6064. + ret = 1;
  6065. +
  6066. + data.count++;
  6067. + s.seqnum = data.count;
  6068. + s.duration = sample;
  6069. + s.outer_duration = outer_sample;
  6070. + s.timestamp = CURRENT_TIME;
  6071. + __buffer_add_sample(&s);
  6072. +
  6073. + /* Keep a running maximum ever recorded hardware latency */
  6074. + if (sample > data.max_sample)
  6075. + data.max_sample = sample;
  6076. + }
  6077. +
  6078. +out:
  6079. + return ret;
  6080. +}
  6081. +
  6082. +/*
  6083. + * kthread_fn - The CPU time sampling/hardware latency detection kernel thread
  6084. + * @unused: A required part of the kthread API.
  6085. + *
  6086. + * Used to periodically sample the CPU TSC via a call to get_sample. We
  6087. + * disable interrupts, which does (intentionally) introduce latency since we
  6088. + * need to ensure nothing else might be running (and thus pre-empting).
  6089. + * Obviously this should never be used in production environments.
  6090. + *
  6091. + * Currently this runs on which ever CPU it was scheduled on, but most
  6092. + * real-worald hardware latency situations occur across several CPUs,
  6093. + * but we might later generalize this if we find there are any actualy
  6094. + * systems with alternate SMI delivery or other hardware latencies.
  6095. + */
  6096. +static int kthread_fn(void *unused)
  6097. +{
  6098. + int ret;
  6099. + u64 interval;
  6100. +
  6101. + while (!kthread_should_stop()) {
  6102. +
  6103. + mutex_lock(&data.lock);
  6104. +
  6105. + local_irq_disable();
  6106. + ret = get_sample();
  6107. + local_irq_enable();
  6108. +
  6109. + if (ret > 0)
  6110. + wake_up(&data.wq); /* wake up reader(s) */
  6111. +
  6112. + interval = data.sample_window - data.sample_width;
  6113. + do_div(interval, USEC_PER_MSEC); /* modifies interval value */
  6114. +
  6115. + mutex_unlock(&data.lock);
  6116. +
  6117. + if (msleep_interruptible(interval))
  6118. + break;
  6119. + }
  6120. +
  6121. + return 0;
  6122. +}
  6123. +
  6124. +/**
  6125. + * start_kthread - Kick off the hardware latency sampling/detector kthread
  6126. + *
  6127. + * This starts a kernel thread that will sit and sample the CPU timestamp
  6128. + * counter (TSC or similar) and look for potential hardware latencies.
  6129. + */
  6130. +static int start_kthread(void)
  6131. +{
  6132. + kthread = kthread_run(kthread_fn, NULL,
  6133. + DRVNAME);
  6134. + if (IS_ERR(kthread)) {
  6135. + pr_err(BANNER "could not start sampling thread\n");
  6136. + enabled = 0;
  6137. + return -ENOMEM;
  6138. + }
  6139. +
  6140. + return 0;
  6141. +}
  6142. +
  6143. +/**
  6144. + * stop_kthread - Inform the hardware latency samping/detector kthread to stop
  6145. + *
  6146. + * This kicks the running hardware latency sampling/detector kernel thread and
  6147. + * tells it to stop sampling now. Use this on unload and at system shutdown.
  6148. + */
  6149. +static int stop_kthread(void)
  6150. +{
  6151. + int ret;
  6152. +
  6153. + ret = kthread_stop(kthread);
  6154. +
  6155. + return ret;
  6156. +}
  6157. +
  6158. +/**
  6159. + * __reset_stats - Reset statistics for the hardware latency detector
  6160. + *
  6161. + * We use data to store various statistics and global state. We call this
  6162. + * function in order to reset those when "enable" is toggled on or off, and
  6163. + * also at initialization. Should be called with data.lock held.
  6164. + */
  6165. +static void __reset_stats(void)
  6166. +{
  6167. + data.count = 0;
  6168. + data.max_sample = 0;
  6169. + ring_buffer_reset(ring_buffer); /* flush out old sample entries */
  6170. +}
  6171. +
  6172. +/**
  6173. + * init_stats - Setup global state statistics for the hardware latency detector
  6174. + *
  6175. + * We use data to store various statistics and global state. We also use
  6176. + * a global ring buffer (ring_buffer) to keep raw samples of detected hardware
  6177. + * induced system latencies. This function initializes these structures and
  6178. + * allocates the global ring buffer also.
  6179. + */
  6180. +static int init_stats(void)
  6181. +{
  6182. + int ret = -ENOMEM;
  6183. +
  6184. + mutex_init(&data.lock);
  6185. + init_waitqueue_head(&data.wq);
  6186. + atomic_set(&data.sample_open, 0);
  6187. +
  6188. + ring_buffer = ring_buffer_alloc(buf_size, BUF_FLAGS);
  6189. +
  6190. + if (WARN(!ring_buffer, KERN_ERR BANNER
  6191. + "failed to allocate ring buffer!\n"))
  6192. + goto out;
  6193. +
  6194. + __reset_stats();
  6195. + data.threshold = threshold ?: DEFAULT_LAT_THRESHOLD; /* threshold us */
  6196. + data.sample_window = DEFAULT_SAMPLE_WINDOW; /* window us */
  6197. + data.sample_width = DEFAULT_SAMPLE_WIDTH; /* width us */
  6198. +
  6199. + ret = 0;
  6200. +
  6201. +out:
  6202. + return ret;
  6203. +
  6204. +}
  6205. +
  6206. +/*
  6207. + * simple_data_read - Wrapper read function for global state debugfs entries
  6208. + * @filp: The active open file structure for the debugfs "file"
  6209. + * @ubuf: The userspace provided buffer to read value into
  6210. + * @cnt: The maximum number of bytes to read
  6211. + * @ppos: The current "file" position
  6212. + * @entry: The entry to read from
  6213. + *
  6214. + * This function provides a generic read implementation for the global state
  6215. + * "data" structure debugfs filesystem entries. It would be nice to use
  6216. + * simple_attr_read directly, but we need to make sure that the data.lock
  6217. + * is held during the actual read.
  6218. + */
  6219. +static ssize_t simple_data_read(struct file *filp, char __user *ubuf,
  6220. + size_t cnt, loff_t *ppos, const u64 *entry)
  6221. +{
  6222. + char buf[U64STR_SIZE];
  6223. + u64 val = 0;
  6224. + int len = 0;
  6225. +
  6226. + memset(buf, 0, sizeof(buf));
  6227. +
  6228. + if (!entry)
  6229. + return -EFAULT;
  6230. +
  6231. + mutex_lock(&data.lock);
  6232. + val = *entry;
  6233. + mutex_unlock(&data.lock);
  6234. +
  6235. + len = snprintf(buf, sizeof(buf), "%llu\n", (unsigned long long)val);
  6236. +
  6237. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
  6238. +
  6239. +}
  6240. +
  6241. +/*
  6242. + * simple_data_write - Wrapper write function for global state debugfs entries
  6243. + * @filp: The active open file structure for the debugfs "file"
  6244. + * @ubuf: The userspace provided buffer to write value from
  6245. + * @cnt: The maximum number of bytes to write
  6246. + * @ppos: The current "file" position
  6247. + * @entry: The entry to write to
  6248. + *
  6249. + * This function provides a generic write implementation for the global state
  6250. + * "data" structure debugfs filesystem entries. It would be nice to use
  6251. + * simple_attr_write directly, but we need to make sure that the data.lock
  6252. + * is held during the actual write.
  6253. + */
  6254. +static ssize_t simple_data_write(struct file *filp, const char __user *ubuf,
  6255. + size_t cnt, loff_t *ppos, u64 *entry)
  6256. +{
  6257. + char buf[U64STR_SIZE];
  6258. + int csize = min(cnt, sizeof(buf));
  6259. + u64 val = 0;
  6260. + int err = 0;
  6261. +
  6262. + memset(buf, '\0', sizeof(buf));
  6263. + if (copy_from_user(buf, ubuf, csize))
  6264. + return -EFAULT;
  6265. +
  6266. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  6267. + err = kstrtoull(buf, 10, &val);
  6268. + if (err)
  6269. + return -EINVAL;
  6270. +
  6271. + mutex_lock(&data.lock);
  6272. + *entry = val;
  6273. + mutex_unlock(&data.lock);
  6274. +
  6275. + return csize;
  6276. +}
  6277. +
  6278. +/**
  6279. + * debug_count_fopen - Open function for "count" debugfs entry
  6280. + * @inode: The in-kernel inode representation of the debugfs "file"
  6281. + * @filp: The active open file structure for the debugfs "file"
  6282. + *
  6283. + * This function provides an open implementation for the "count" debugfs
  6284. + * interface to the hardware latency detector.
  6285. + */
  6286. +static int debug_count_fopen(struct inode *inode, struct file *filp)
  6287. +{
  6288. + return 0;
  6289. +}
  6290. +
  6291. +/**
  6292. + * debug_count_fread - Read function for "count" debugfs entry
  6293. + * @filp: The active open file structure for the debugfs "file"
  6294. + * @ubuf: The userspace provided buffer to read value into
  6295. + * @cnt: The maximum number of bytes to read
  6296. + * @ppos: The current "file" position
  6297. + *
  6298. + * This function provides a read implementation for the "count" debugfs
  6299. + * interface to the hardware latency detector. Can be used to read the
  6300. + * number of latency readings exceeding the configured threshold since
  6301. + * the detector was last reset (e.g. by writing a zero into "count").
  6302. + */
  6303. +static ssize_t debug_count_fread(struct file *filp, char __user *ubuf,
  6304. + size_t cnt, loff_t *ppos)
  6305. +{
  6306. + return simple_data_read(filp, ubuf, cnt, ppos, &data.count);
  6307. +}
  6308. +
  6309. +/**
  6310. + * debug_count_fwrite - Write function for "count" debugfs entry
  6311. + * @filp: The active open file structure for the debugfs "file"
  6312. + * @ubuf: The user buffer that contains the value to write
  6313. + * @cnt: The maximum number of bytes to write to "file"
  6314. + * @ppos: The current position in the debugfs "file"
  6315. + *
  6316. + * This function provides a write implementation for the "count" debugfs
  6317. + * interface to the hardware latency detector. Can be used to write a
  6318. + * desired value, especially to zero the total count.
  6319. + */
  6320. +static ssize_t debug_count_fwrite(struct file *filp,
  6321. + const char __user *ubuf,
  6322. + size_t cnt,
  6323. + loff_t *ppos)
  6324. +{
  6325. + return simple_data_write(filp, ubuf, cnt, ppos, &data.count);
  6326. +}
  6327. +
  6328. +/**
  6329. + * debug_enable_fopen - Dummy open function for "enable" debugfs interface
  6330. + * @inode: The in-kernel inode representation of the debugfs "file"
  6331. + * @filp: The active open file structure for the debugfs "file"
  6332. + *
  6333. + * This function provides an open implementation for the "enable" debugfs
  6334. + * interface to the hardware latency detector.
  6335. + */
  6336. +static int debug_enable_fopen(struct inode *inode, struct file *filp)
  6337. +{
  6338. + return 0;
  6339. +}
  6340. +
  6341. +/**
  6342. + * debug_enable_fread - Read function for "enable" debugfs interface
  6343. + * @filp: The active open file structure for the debugfs "file"
  6344. + * @ubuf: The userspace provided buffer to read value into
  6345. + * @cnt: The maximum number of bytes to read
  6346. + * @ppos: The current "file" position
  6347. + *
  6348. + * This function provides a read implementation for the "enable" debugfs
  6349. + * interface to the hardware latency detector. Can be used to determine
  6350. + * whether the detector is currently enabled ("0\n" or "1\n" returned).
  6351. + */
  6352. +static ssize_t debug_enable_fread(struct file *filp, char __user *ubuf,
  6353. + size_t cnt, loff_t *ppos)
  6354. +{
  6355. + char buf[4];
  6356. +
  6357. + if ((cnt < sizeof(buf)) || (*ppos))
  6358. + return 0;
  6359. +
  6360. + buf[0] = enabled ? '1' : '0';
  6361. + buf[1] = '\n';
  6362. + buf[2] = '\0';
  6363. + if (copy_to_user(ubuf, buf, strlen(buf)))
  6364. + return -EFAULT;
  6365. + return *ppos = strlen(buf);
  6366. +}
  6367. +
  6368. +/**
  6369. + * debug_enable_fwrite - Write function for "enable" debugfs interface
  6370. + * @filp: The active open file structure for the debugfs "file"
  6371. + * @ubuf: The user buffer that contains the value to write
  6372. + * @cnt: The maximum number of bytes to write to "file"
  6373. + * @ppos: The current position in the debugfs "file"
  6374. + *
  6375. + * This function provides a write implementation for the "enable" debugfs
  6376. + * interface to the hardware latency detector. Can be used to enable or
  6377. + * disable the detector, which will have the side-effect of possibly
  6378. + * also resetting the global stats and kicking off the measuring
  6379. + * kthread (on an enable) or the converse (upon a disable).
  6380. + */
  6381. +static ssize_t debug_enable_fwrite(struct file *filp,
  6382. + const char __user *ubuf,
  6383. + size_t cnt,
  6384. + loff_t *ppos)
  6385. +{
  6386. + char buf[4];
  6387. + int csize = min(cnt, sizeof(buf));
  6388. + long val = 0;
  6389. + int err = 0;
  6390. +
  6391. + memset(buf, '\0', sizeof(buf));
  6392. + if (copy_from_user(buf, ubuf, csize))
  6393. + return -EFAULT;
  6394. +
  6395. + buf[sizeof(buf)-1] = '\0'; /* just in case */
  6396. + err = kstrtoul(buf, 10, &val);
  6397. + if (0 != err)
  6398. + return -EINVAL;
  6399. +
  6400. + if (val) {
  6401. + if (enabled)
  6402. + goto unlock;
  6403. + enabled = 1;
  6404. + __reset_stats();
  6405. + if (start_kthread())
  6406. + return -EFAULT;
  6407. + } else {
  6408. + if (!enabled)
  6409. + goto unlock;
  6410. + enabled = 0;
  6411. + err = stop_kthread();
  6412. + if (err) {
  6413. + pr_err(BANNER "cannot stop kthread\n");
  6414. + return -EFAULT;
  6415. + }
  6416. + wake_up(&data.wq); /* reader(s) should return */
  6417. + }
  6418. +unlock:
  6419. + return csize;
  6420. +}
  6421. +
  6422. +/**
  6423. + * debug_max_fopen - Open function for "max" debugfs entry
  6424. + * @inode: The in-kernel inode representation of the debugfs "file"
  6425. + * @filp: The active open file structure for the debugfs "file"
  6426. + *
  6427. + * This function provides an open implementation for the "max" debugfs
  6428. + * interface to the hardware latency detector.
  6429. + */
  6430. +static int debug_max_fopen(struct inode *inode, struct file *filp)
  6431. +{
  6432. + return 0;
  6433. +}
  6434. +
  6435. +/**
  6436. + * debug_max_fread - Read function for "max" debugfs entry
  6437. + * @filp: The active open file structure for the debugfs "file"
  6438. + * @ubuf: The userspace provided buffer to read value into
  6439. + * @cnt: The maximum number of bytes to read
  6440. + * @ppos: The current "file" position
  6441. + *
  6442. + * This function provides a read implementation for the "max" debugfs
  6443. + * interface to the hardware latency detector. Can be used to determine
  6444. + * the maximum latency value observed since it was last reset.
  6445. + */
  6446. +static ssize_t debug_max_fread(struct file *filp, char __user *ubuf,
  6447. + size_t cnt, loff_t *ppos)
  6448. +{
  6449. + return simple_data_read(filp, ubuf, cnt, ppos, &data.max_sample);
  6450. +}
  6451. +
  6452. +/**
  6453. + * debug_max_fwrite - Write function for "max" debugfs entry
  6454. + * @filp: The active open file structure for the debugfs "file"
  6455. + * @ubuf: The user buffer that contains the value to write
  6456. + * @cnt: The maximum number of bytes to write to "file"
  6457. + * @ppos: The current position in the debugfs "file"
  6458. + *
  6459. + * This function provides a write implementation for the "max" debugfs
  6460. + * interface to the hardware latency detector. Can be used to reset the
  6461. + * maximum or set it to some other desired value - if, then, subsequent
  6462. + * measurements exceed this value, the maximum will be updated.
  6463. + */
  6464. +static ssize_t debug_max_fwrite(struct file *filp,
  6465. + const char __user *ubuf,
  6466. + size_t cnt,
  6467. + loff_t *ppos)
  6468. +{
  6469. + return simple_data_write(filp, ubuf, cnt, ppos, &data.max_sample);
  6470. +}
  6471. +
  6472. +
  6473. +/**
  6474. + * debug_sample_fopen - An open function for "sample" debugfs interface
  6475. + * @inode: The in-kernel inode representation of this debugfs "file"
  6476. + * @filp: The active open file structure for the debugfs "file"
  6477. + *
  6478. + * This function handles opening the "sample" file within the hardware
  6479. + * latency detector debugfs directory interface. This file is used to read
  6480. + * raw samples from the global ring_buffer and allows the user to see a
  6481. + * running latency history. Can be opened blocking or non-blocking,
  6482. + * affecting whether it behaves as a buffer read pipe, or does not.
  6483. + * Implements simple locking to prevent multiple simultaneous use.
  6484. + */
  6485. +static int debug_sample_fopen(struct inode *inode, struct file *filp)
  6486. +{
  6487. + if (!atomic_add_unless(&data.sample_open, 1, 1))
  6488. + return -EBUSY;
  6489. + else
  6490. + return 0;
  6491. +}
  6492. +
  6493. +/**
  6494. + * debug_sample_fread - A read function for "sample" debugfs interface
  6495. + * @filp: The active open file structure for the debugfs "file"
  6496. + * @ubuf: The user buffer that will contain the samples read
  6497. + * @cnt: The maximum bytes to read from the debugfs "file"
  6498. + * @ppos: The current position in the debugfs "file"
  6499. + *
  6500. + * This function handles reading from the "sample" file within the hardware
  6501. + * latency detector debugfs directory interface. This file is used to read
  6502. + * raw samples from the global ring_buffer and allows the user to see a
  6503. + * running latency history. By default this will block pending a new
  6504. + * value written into the sample buffer, unless there are already a
  6505. + * number of value(s) waiting in the buffer, or the sample file was
  6506. + * previously opened in a non-blocking mode of operation.
  6507. + */
  6508. +static ssize_t debug_sample_fread(struct file *filp, char __user *ubuf,
  6509. + size_t cnt, loff_t *ppos)
  6510. +{
  6511. + int len = 0;
  6512. + char buf[64];
  6513. + struct sample *sample = NULL;
  6514. +
  6515. + if (!enabled)
  6516. + return 0;
  6517. +
  6518. + sample = kzalloc(sizeof(struct sample), GFP_KERNEL);
  6519. + if (!sample)
  6520. + return -ENOMEM;
  6521. +
  6522. + while (!buffer_get_sample(sample)) {
  6523. +
  6524. + DEFINE_WAIT(wait);
  6525. +
  6526. + if (filp->f_flags & O_NONBLOCK) {
  6527. + len = -EAGAIN;
  6528. + goto out;
  6529. + }
  6530. +
  6531. + prepare_to_wait(&data.wq, &wait, TASK_INTERRUPTIBLE);
  6532. + schedule();
  6533. + finish_wait(&data.wq, &wait);
  6534. +
  6535. + if (signal_pending(current)) {
  6536. + len = -EINTR;
  6537. + goto out;
  6538. + }
  6539. +
  6540. + if (!enabled) { /* enable was toggled */
  6541. + len = 0;
  6542. + goto out;
  6543. + }
  6544. + }
  6545. +
  6546. + len = snprintf(buf, sizeof(buf), "%010lu.%010lu\t%llu\t%llu\n",
  6547. + sample->timestamp.tv_sec,
  6548. + sample->timestamp.tv_nsec,
  6549. + sample->duration,
  6550. + sample->outer_duration);
  6551. +
  6552. +
  6553. + /* handling partial reads is more trouble than it's worth */
  6554. + if (len > cnt)
  6555. + goto out;
  6556. +
  6557. + if (copy_to_user(ubuf, buf, len))
  6558. + len = -EFAULT;
  6559. +
  6560. +out:
  6561. + kfree(sample);
  6562. + return len;
  6563. +}
  6564. +
  6565. +/**
  6566. + * debug_sample_release - Release function for "sample" debugfs interface
  6567. + * @inode: The in-kernel inode represenation of the debugfs "file"
  6568. + * @filp: The active open file structure for the debugfs "file"
  6569. + *
  6570. + * This function completes the close of the debugfs interface "sample" file.
  6571. + * Frees the sample_open "lock" so that other users may open the interface.
  6572. + */
  6573. +static int debug_sample_release(struct inode *inode, struct file *filp)
  6574. +{
  6575. + atomic_dec(&data.sample_open);
  6576. +
  6577. + return 0;
  6578. +}
  6579. +
  6580. +/**
  6581. + * debug_threshold_fopen - Open function for "threshold" debugfs entry
  6582. + * @inode: The in-kernel inode representation of the debugfs "file"
  6583. + * @filp: The active open file structure for the debugfs "file"
  6584. + *
  6585. + * This function provides an open implementation for the "threshold" debugfs
  6586. + * interface to the hardware latency detector.
  6587. + */
  6588. +static int debug_threshold_fopen(struct inode *inode, struct file *filp)
  6589. +{
  6590. + return 0;
  6591. +}
  6592. +
  6593. +/**
  6594. + * debug_threshold_fread - Read function for "threshold" debugfs entry
  6595. + * @filp: The active open file structure for the debugfs "file"
  6596. + * @ubuf: The userspace provided buffer to read value into
  6597. + * @cnt: The maximum number of bytes to read
  6598. + * @ppos: The current "file" position
  6599. + *
  6600. + * This function provides a read implementation for the "threshold" debugfs
  6601. + * interface to the hardware latency detector. It can be used to determine
  6602. + * the current threshold level at which a latency will be recorded in the
  6603. + * global ring buffer, typically on the order of 10us.
  6604. + */
  6605. +static ssize_t debug_threshold_fread(struct file *filp, char __user *ubuf,
  6606. + size_t cnt, loff_t *ppos)
  6607. +{
  6608. + return simple_data_read(filp, ubuf, cnt, ppos, &data.threshold);
  6609. +}
  6610. +
  6611. +/**
  6612. + * debug_threshold_fwrite - Write function for "threshold" debugfs entry
  6613. + * @filp: The active open file structure for the debugfs "file"
  6614. + * @ubuf: The user buffer that contains the value to write
  6615. + * @cnt: The maximum number of bytes to write to "file"
  6616. + * @ppos: The current position in the debugfs "file"
  6617. + *
  6618. + * This function provides a write implementation for the "threshold" debugfs
  6619. + * interface to the hardware latency detector. It can be used to configure
  6620. + * the threshold level at which any subsequently detected latencies will
  6621. + * be recorded into the global ring buffer.
  6622. + */
  6623. +static ssize_t debug_threshold_fwrite(struct file *filp,
  6624. + const char __user *ubuf,
  6625. + size_t cnt,
  6626. + loff_t *ppos)
  6627. +{
  6628. + int ret;
  6629. +
  6630. + ret = simple_data_write(filp, ubuf, cnt, ppos, &data.threshold);
  6631. +
  6632. + if (enabled)
  6633. + wake_up_process(kthread);
  6634. +
  6635. + return ret;
  6636. +}
  6637. +
  6638. +/**
  6639. + * debug_width_fopen - Open function for "width" debugfs entry
  6640. + * @inode: The in-kernel inode representation of the debugfs "file"
  6641. + * @filp: The active open file structure for the debugfs "file"
  6642. + *
  6643. + * This function provides an open implementation for the "width" debugfs
  6644. + * interface to the hardware latency detector.
  6645. + */
  6646. +static int debug_width_fopen(struct inode *inode, struct file *filp)
  6647. +{
  6648. + return 0;
  6649. +}
  6650. +
  6651. +/**
  6652. + * debug_width_fread - Read function for "width" debugfs entry
  6653. + * @filp: The active open file structure for the debugfs "file"
  6654. + * @ubuf: The userspace provided buffer to read value into
  6655. + * @cnt: The maximum number of bytes to read
  6656. + * @ppos: The current "file" position
  6657. + *
  6658. + * This function provides a read implementation for the "width" debugfs
  6659. + * interface to the hardware latency detector. It can be used to determine
  6660. + * for how many us of the total window us we will actively sample for any
  6661. + * hardware-induced latecy periods. Obviously, it is not possible to
  6662. + * sample constantly and have the system respond to a sample reader, or,
  6663. + * worse, without having the system appear to have gone out to lunch.
  6664. + */
  6665. +static ssize_t debug_width_fread(struct file *filp, char __user *ubuf,
  6666. + size_t cnt, loff_t *ppos)
  6667. +{
  6668. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_width);
  6669. +}
  6670. +
  6671. +/**
  6672. + * debug_width_fwrite - Write function for "width" debugfs entry
  6673. + * @filp: The active open file structure for the debugfs "file"
  6674. + * @ubuf: The user buffer that contains the value to write
  6675. + * @cnt: The maximum number of bytes to write to "file"
  6676. + * @ppos: The current position in the debugfs "file"
  6677. + *
  6678. + * This function provides a write implementation for the "width" debugfs
  6679. + * interface to the hardware latency detector. It can be used to configure
  6680. + * for how many us of the total window us we will actively sample for any
  6681. + * hardware-induced latency periods. Obviously, it is not possible to
  6682. + * sample constantly and have the system respond to a sample reader, or,
  6683. + * worse, without having the system appear to have gone out to lunch. It
  6684. + * is enforced that width is less that the total window size.
  6685. + */
  6686. +static ssize_t debug_width_fwrite(struct file *filp,
  6687. + const char __user *ubuf,
  6688. + size_t cnt,
  6689. + loff_t *ppos)
  6690. +{
  6691. + char buf[U64STR_SIZE];
  6692. + int csize = min(cnt, sizeof(buf));
  6693. + u64 val = 0;
  6694. + int err = 0;
  6695. +
  6696. + memset(buf, '\0', sizeof(buf));
  6697. + if (copy_from_user(buf, ubuf, csize))
  6698. + return -EFAULT;
  6699. +
  6700. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  6701. + err = kstrtoull(buf, 10, &val);
  6702. + if (0 != err)
  6703. + return -EINVAL;
  6704. +
  6705. + mutex_lock(&data.lock);
  6706. + if (val < data.sample_window)
  6707. + data.sample_width = val;
  6708. + else {
  6709. + mutex_unlock(&data.lock);
  6710. + return -EINVAL;
  6711. + }
  6712. + mutex_unlock(&data.lock);
  6713. +
  6714. + if (enabled)
  6715. + wake_up_process(kthread);
  6716. +
  6717. + return csize;
  6718. +}
  6719. +
  6720. +/**
  6721. + * debug_window_fopen - Open function for "window" debugfs entry
  6722. + * @inode: The in-kernel inode representation of the debugfs "file"
  6723. + * @filp: The active open file structure for the debugfs "file"
  6724. + *
  6725. + * This function provides an open implementation for the "window" debugfs
  6726. + * interface to the hardware latency detector. The window is the total time
  6727. + * in us that will be considered one sample period. Conceptually, windows
  6728. + * occur back-to-back and contain a sample width period during which
  6729. + * actual sampling occurs.
  6730. + */
  6731. +static int debug_window_fopen(struct inode *inode, struct file *filp)
  6732. +{
  6733. + return 0;
  6734. +}
  6735. +
  6736. +/**
  6737. + * debug_window_fread - Read function for "window" debugfs entry
  6738. + * @filp: The active open file structure for the debugfs "file"
  6739. + * @ubuf: The userspace provided buffer to read value into
  6740. + * @cnt: The maximum number of bytes to read
  6741. + * @ppos: The current "file" position
  6742. + *
  6743. + * This function provides a read implementation for the "window" debugfs
  6744. + * interface to the hardware latency detector. The window is the total time
  6745. + * in us that will be considered one sample period. Conceptually, windows
  6746. + * occur back-to-back and contain a sample width period during which
  6747. + * actual sampling occurs. Can be used to read the total window size.
  6748. + */
  6749. +static ssize_t debug_window_fread(struct file *filp, char __user *ubuf,
  6750. + size_t cnt, loff_t *ppos)
  6751. +{
  6752. + return simple_data_read(filp, ubuf, cnt, ppos, &data.sample_window);
  6753. +}
  6754. +
  6755. +/**
  6756. + * debug_window_fwrite - Write function for "window" debugfs entry
  6757. + * @filp: The active open file structure for the debugfs "file"
  6758. + * @ubuf: The user buffer that contains the value to write
  6759. + * @cnt: The maximum number of bytes to write to "file"
  6760. + * @ppos: The current position in the debugfs "file"
  6761. + *
  6762. + * This function provides a write implementation for the "window" debufds
  6763. + * interface to the hardware latency detetector. The window is the total time
  6764. + * in us that will be considered one sample period. Conceptually, windows
  6765. + * occur back-to-back and contain a sample width period during which
  6766. + * actual sampling occurs. Can be used to write a new total window size. It
  6767. + * is enfoced that any value written must be greater than the sample width
  6768. + * size, or an error results.
  6769. + */
  6770. +static ssize_t debug_window_fwrite(struct file *filp,
  6771. + const char __user *ubuf,
  6772. + size_t cnt,
  6773. + loff_t *ppos)
  6774. +{
  6775. + char buf[U64STR_SIZE];
  6776. + int csize = min(cnt, sizeof(buf));
  6777. + u64 val = 0;
  6778. + int err = 0;
  6779. +
  6780. + memset(buf, '\0', sizeof(buf));
  6781. + if (copy_from_user(buf, ubuf, csize))
  6782. + return -EFAULT;
  6783. +
  6784. + buf[U64STR_SIZE-1] = '\0'; /* just in case */
  6785. + err = kstrtoull(buf, 10, &val);
  6786. + if (0 != err)
  6787. + return -EINVAL;
  6788. +
  6789. + mutex_lock(&data.lock);
  6790. + if (data.sample_width < val)
  6791. + data.sample_window = val;
  6792. + else {
  6793. + mutex_unlock(&data.lock);
  6794. + return -EINVAL;
  6795. + }
  6796. + mutex_unlock(&data.lock);
  6797. +
  6798. + return csize;
  6799. +}
  6800. +
  6801. +/*
  6802. + * Function pointers for the "count" debugfs file operations
  6803. + */
  6804. +static const struct file_operations count_fops = {
  6805. + .open = debug_count_fopen,
  6806. + .read = debug_count_fread,
  6807. + .write = debug_count_fwrite,
  6808. + .owner = THIS_MODULE,
  6809. +};
  6810. +
  6811. +/*
  6812. + * Function pointers for the "enable" debugfs file operations
  6813. + */
  6814. +static const struct file_operations enable_fops = {
  6815. + .open = debug_enable_fopen,
  6816. + .read = debug_enable_fread,
  6817. + .write = debug_enable_fwrite,
  6818. + .owner = THIS_MODULE,
  6819. +};
  6820. +
  6821. +/*
  6822. + * Function pointers for the "max" debugfs file operations
  6823. + */
  6824. +static const struct file_operations max_fops = {
  6825. + .open = debug_max_fopen,
  6826. + .read = debug_max_fread,
  6827. + .write = debug_max_fwrite,
  6828. + .owner = THIS_MODULE,
  6829. +};
  6830. +
  6831. +/*
  6832. + * Function pointers for the "sample" debugfs file operations
  6833. + */
  6834. +static const struct file_operations sample_fops = {
  6835. + .open = debug_sample_fopen,
  6836. + .read = debug_sample_fread,
  6837. + .release = debug_sample_release,
  6838. + .owner = THIS_MODULE,
  6839. +};
  6840. +
  6841. +/*
  6842. + * Function pointers for the "threshold" debugfs file operations
  6843. + */
  6844. +static const struct file_operations threshold_fops = {
  6845. + .open = debug_threshold_fopen,
  6846. + .read = debug_threshold_fread,
  6847. + .write = debug_threshold_fwrite,
  6848. + .owner = THIS_MODULE,
  6849. +};
  6850. +
  6851. +/*
  6852. + * Function pointers for the "width" debugfs file operations
  6853. + */
  6854. +static const struct file_operations width_fops = {
  6855. + .open = debug_width_fopen,
  6856. + .read = debug_width_fread,
  6857. + .write = debug_width_fwrite,
  6858. + .owner = THIS_MODULE,
  6859. +};
  6860. +
  6861. +/*
  6862. + * Function pointers for the "window" debugfs file operations
  6863. + */
  6864. +static const struct file_operations window_fops = {
  6865. + .open = debug_window_fopen,
  6866. + .read = debug_window_fread,
  6867. + .write = debug_window_fwrite,
  6868. + .owner = THIS_MODULE,
  6869. +};
  6870. +
  6871. +/**
  6872. + * init_debugfs - A function to initialize the debugfs interface files
  6873. + *
  6874. + * This function creates entries in debugfs for "hwlat_detector", including
  6875. + * files to read values from the detector, current samples, and the
  6876. + * maximum sample that has been captured since the hardware latency
  6877. + * dectector was started.
  6878. + */
  6879. +static int init_debugfs(void)
  6880. +{
  6881. + int ret = -ENOMEM;
  6882. +
  6883. + debug_dir = debugfs_create_dir(DRVNAME, NULL);
  6884. + if (!debug_dir)
  6885. + goto err_debug_dir;
  6886. +
  6887. + debug_sample = debugfs_create_file("sample", 0444,
  6888. + debug_dir, NULL,
  6889. + &sample_fops);
  6890. + if (!debug_sample)
  6891. + goto err_sample;
  6892. +
  6893. + debug_count = debugfs_create_file("count", 0444,
  6894. + debug_dir, NULL,
  6895. + &count_fops);
  6896. + if (!debug_count)
  6897. + goto err_count;
  6898. +
  6899. + debug_max = debugfs_create_file("max", 0444,
  6900. + debug_dir, NULL,
  6901. + &max_fops);
  6902. + if (!debug_max)
  6903. + goto err_max;
  6904. +
  6905. + debug_sample_window = debugfs_create_file("window", 0644,
  6906. + debug_dir, NULL,
  6907. + &window_fops);
  6908. + if (!debug_sample_window)
  6909. + goto err_window;
  6910. +
  6911. + debug_sample_width = debugfs_create_file("width", 0644,
  6912. + debug_dir, NULL,
  6913. + &width_fops);
  6914. + if (!debug_sample_width)
  6915. + goto err_width;
  6916. +
  6917. + debug_threshold = debugfs_create_file("threshold", 0644,
  6918. + debug_dir, NULL,
  6919. + &threshold_fops);
  6920. + if (!debug_threshold)
  6921. + goto err_threshold;
  6922. +
  6923. + debug_enable = debugfs_create_file("enable", 0644,
  6924. + debug_dir, &enabled,
  6925. + &enable_fops);
  6926. + if (!debug_enable)
  6927. + goto err_enable;
  6928. +
  6929. + else {
  6930. + ret = 0;
  6931. + goto out;
  6932. + }
  6933. +
  6934. +err_enable:
  6935. + debugfs_remove(debug_threshold);
  6936. +err_threshold:
  6937. + debugfs_remove(debug_sample_width);
  6938. +err_width:
  6939. + debugfs_remove(debug_sample_window);
  6940. +err_window:
  6941. + debugfs_remove(debug_max);
  6942. +err_max:
  6943. + debugfs_remove(debug_count);
  6944. +err_count:
  6945. + debugfs_remove(debug_sample);
  6946. +err_sample:
  6947. + debugfs_remove(debug_dir);
  6948. +err_debug_dir:
  6949. +out:
  6950. + return ret;
  6951. +}
  6952. +
  6953. +/**
  6954. + * free_debugfs - A function to cleanup the debugfs file interface
  6955. + */
  6956. +static void free_debugfs(void)
  6957. +{
  6958. + /* could also use a debugfs_remove_recursive */
  6959. + debugfs_remove(debug_enable);
  6960. + debugfs_remove(debug_threshold);
  6961. + debugfs_remove(debug_sample_width);
  6962. + debugfs_remove(debug_sample_window);
  6963. + debugfs_remove(debug_max);
  6964. + debugfs_remove(debug_count);
  6965. + debugfs_remove(debug_sample);
  6966. + debugfs_remove(debug_dir);
  6967. +}
  6968. +
  6969. +/**
  6970. + * detector_init - Standard module initialization code
  6971. + */
  6972. +static int detector_init(void)
  6973. +{
  6974. + int ret = -ENOMEM;
  6975. +
  6976. + pr_info(BANNER "version %s\n", VERSION);
  6977. +
  6978. + ret = init_stats();
  6979. + if (0 != ret)
  6980. + goto out;
  6981. +
  6982. + ret = init_debugfs();
  6983. + if (0 != ret)
  6984. + goto err_stats;
  6985. +
  6986. + if (enabled)
  6987. + ret = start_kthread();
  6988. +
  6989. + goto out;
  6990. +
  6991. +err_stats:
  6992. + ring_buffer_free(ring_buffer);
  6993. +out:
  6994. + return ret;
  6995. +
  6996. +}
  6997. +
  6998. +/**
  6999. + * detector_exit - Standard module cleanup code
  7000. + */
  7001. +static void detector_exit(void)
  7002. +{
  7003. + int err;
  7004. +
  7005. + if (enabled) {
  7006. + enabled = 0;
  7007. + err = stop_kthread();
  7008. + if (err)
  7009. + pr_err(BANNER "cannot stop kthread\n");
  7010. + }
  7011. +
  7012. + free_debugfs();
  7013. + ring_buffer_free(ring_buffer); /* free up the ring buffer */
  7014. +
  7015. +}
  7016. +
  7017. +module_init(detector_init);
  7018. +module_exit(detector_exit);
  7019. diff -Nur linux-4.1.6.orig/drivers/misc/Kconfig linux-4.1.6/drivers/misc/Kconfig
  7020. --- linux-4.1.6.orig/drivers/misc/Kconfig 2015-08-17 05:52:51.000000000 +0200
  7021. +++ linux-4.1.6/drivers/misc/Kconfig 2015-09-08 23:49:06.082091803 +0200
  7022. @@ -54,6 +54,7 @@
  7023. config ATMEL_TCLIB
  7024. bool "Atmel AT32/AT91 Timer/Counter Library"
  7025. depends on (AVR32 || ARCH_AT91)
  7026. + default y if PREEMPT_RT_FULL
  7027. help
  7028. Select this if you want a library to allocate the Timer/Counter
  7029. blocks found on many Atmel processors. This facilitates using
  7030. @@ -69,8 +70,7 @@
  7031. are combined to make a single 32-bit timer.
  7032. When GENERIC_CLOCKEVENTS is defined, the third timer channel
  7033. - may be used as a clock event device supporting oneshot mode
  7034. - (delays of up to two seconds) based on the 32 KiHz clock.
  7035. + may be used as a clock event device supporting oneshot mode.
  7036. config ATMEL_TCB_CLKSRC_BLOCK
  7037. int
  7038. @@ -84,6 +84,15 @@
  7039. TC can be used for other purposes, such as PWM generation and
  7040. interval timing.
  7041. +config ATMEL_TCB_CLKSRC_USE_SLOW_CLOCK
  7042. + bool "TC Block use 32 KiHz clock"
  7043. + depends on ATMEL_TCB_CLKSRC
  7044. + default y if !PREEMPT_RT_FULL
  7045. + help
  7046. + Select this to use 32 KiHz base clock rate as TC block clock
  7047. + source for clock events.
  7048. +
  7049. +
  7050. config DUMMY_IRQ
  7051. tristate "Dummy IRQ handler"
  7052. default n
  7053. @@ -113,6 +122,35 @@
  7054. for information on the specific driver level and support statement
  7055. for your IBM server.
  7056. +config HWLAT_DETECTOR
  7057. + tristate "Testing module to detect hardware-induced latencies"
  7058. + depends on DEBUG_FS
  7059. + depends on RING_BUFFER
  7060. + default m
  7061. + ---help---
  7062. + A simple hardware latency detector. Use this module to detect
  7063. + large latencies introduced by the behavior of the underlying
  7064. + system firmware external to Linux. We do this using periodic
  7065. + use of stop_machine to grab all available CPUs and measure
  7066. + for unexplainable gaps in the CPU timestamp counter(s). By
  7067. + default, the module is not enabled until the "enable" file
  7068. + within the "hwlat_detector" debugfs directory is toggled.
  7069. +
  7070. + This module is often used to detect SMI (System Management
  7071. + Interrupts) on x86 systems, though is not x86 specific. To
  7072. + this end, we default to using a sample window of 1 second,
  7073. + during which we will sample for 0.5 seconds. If an SMI or
  7074. + similar event occurs during that time, it is recorded
  7075. + into an 8K samples global ring buffer until retreived.
  7076. +
  7077. + WARNING: This software should never be enabled (it can be built
  7078. + but should not be turned on after it is loaded) in a production
  7079. + environment where high latencies are a concern since the
  7080. + sampling mechanism actually introduces latencies for
  7081. + regular tasks while the CPU(s) are being held.
  7082. +
  7083. + If unsure, say N
  7084. +
  7085. config PHANTOM
  7086. tristate "Sensable PHANToM (PCI)"
  7087. depends on PCI
  7088. diff -Nur linux-4.1.6.orig/drivers/misc/Makefile linux-4.1.6/drivers/misc/Makefile
  7089. --- linux-4.1.6.orig/drivers/misc/Makefile 2015-08-17 05:52:51.000000000 +0200
  7090. +++ linux-4.1.6/drivers/misc/Makefile 2015-09-08 23:49:06.082091803 +0200
  7091. @@ -38,6 +38,7 @@
  7092. obj-$(CONFIG_HMC6352) += hmc6352.o
  7093. obj-y += eeprom/
  7094. obj-y += cb710/
  7095. +obj-$(CONFIG_HWLAT_DETECTOR) += hwlat_detector.o
  7096. obj-$(CONFIG_SPEAR13XX_PCIE_GADGET) += spear13xx_pcie_gadget.o
  7097. obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o
  7098. obj-$(CONFIG_ARM_CHARLCD) += arm-charlcd.o
  7099. diff -Nur linux-4.1.6.orig/drivers/mmc/host/mmci.c linux-4.1.6/drivers/mmc/host/mmci.c
  7100. --- linux-4.1.6.orig/drivers/mmc/host/mmci.c 2015-08-17 05:52:51.000000000 +0200
  7101. +++ linux-4.1.6/drivers/mmc/host/mmci.c 2015-09-08 23:49:06.082091803 +0200
  7102. @@ -1155,15 +1155,12 @@
  7103. struct sg_mapping_iter *sg_miter = &host->sg_miter;
  7104. struct variant_data *variant = host->variant;
  7105. void __iomem *base = host->base;
  7106. - unsigned long flags;
  7107. u32 status;
  7108. status = readl(base + MMCISTATUS);
  7109. dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
  7110. - local_irq_save(flags);
  7111. -
  7112. do {
  7113. unsigned int remain, len;
  7114. char *buffer;
  7115. @@ -1203,8 +1200,6 @@
  7116. sg_miter_stop(sg_miter);
  7117. - local_irq_restore(flags);
  7118. -
  7119. /*
  7120. * If we have less than the fifo 'half-full' threshold to transfer,
  7121. * trigger a PIO interrupt as soon as any data is available.
  7122. diff -Nur linux-4.1.6.orig/drivers/mmc/host/sdhci.c linux-4.1.6/drivers/mmc/host/sdhci.c
  7123. --- linux-4.1.6.orig/drivers/mmc/host/sdhci.c 2015-08-17 05:52:51.000000000 +0200
  7124. +++ linux-4.1.6/drivers/mmc/host/sdhci.c 2015-09-08 23:49:06.082091803 +0200
  7125. @@ -2691,6 +2691,31 @@
  7126. return isr ? IRQ_HANDLED : IRQ_NONE;
  7127. }
  7128. +#ifdef CONFIG_PREEMPT_RT_BASE
  7129. +static irqreturn_t sdhci_rt_irq(int irq, void *dev_id)
  7130. +{
  7131. + irqreturn_t ret;
  7132. +
  7133. + local_bh_disable();
  7134. + ret = sdhci_irq(irq, dev_id);
  7135. + local_bh_enable();
  7136. + if (ret == IRQ_WAKE_THREAD)
  7137. + ret = sdhci_thread_irq(irq, dev_id);
  7138. + return ret;
  7139. +}
  7140. +#endif
  7141. +
  7142. +static int sdhci_req_irq(struct sdhci_host *host)
  7143. +{
  7144. +#ifdef CONFIG_PREEMPT_RT_BASE
  7145. + return request_threaded_irq(host->irq, NULL, sdhci_rt_irq,
  7146. + IRQF_SHARED, mmc_hostname(host->mmc), host);
  7147. +#else
  7148. + return request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq,
  7149. + IRQF_SHARED, mmc_hostname(host->mmc), host);
  7150. +#endif
  7151. +}
  7152. +
  7153. /*****************************************************************************\
  7154. * *
  7155. * Suspend/resume *
  7156. @@ -2758,9 +2783,7 @@
  7157. }
  7158. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  7159. - ret = request_threaded_irq(host->irq, sdhci_irq,
  7160. - sdhci_thread_irq, IRQF_SHARED,
  7161. - mmc_hostname(host->mmc), host);
  7162. + ret = sdhci_req_irq(host);
  7163. if (ret)
  7164. return ret;
  7165. } else {
  7166. @@ -3421,8 +3444,7 @@
  7167. sdhci_init(host, 0);
  7168. - ret = request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq,
  7169. - IRQF_SHARED, mmc_hostname(mmc), host);
  7170. + ret = sdhci_req_irq(host);
  7171. if (ret) {
  7172. pr_err("%s: Failed to request IRQ %d: %d\n",
  7173. mmc_hostname(mmc), host->irq, ret);
  7174. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/3com/3c59x.c linux-4.1.6/drivers/net/ethernet/3com/3c59x.c
  7175. --- linux-4.1.6.orig/drivers/net/ethernet/3com/3c59x.c 2015-08-17 05:52:51.000000000 +0200
  7176. +++ linux-4.1.6/drivers/net/ethernet/3com/3c59x.c 2015-09-08 23:49:06.086091361 +0200
  7177. @@ -842,9 +842,9 @@
  7178. {
  7179. struct vortex_private *vp = netdev_priv(dev);
  7180. unsigned long flags;
  7181. - local_irq_save(flags);
  7182. + local_irq_save_nort(flags);
  7183. (vp->full_bus_master_rx ? boomerang_interrupt:vortex_interrupt)(dev->irq,dev);
  7184. - local_irq_restore(flags);
  7185. + local_irq_restore_nort(flags);
  7186. }
  7187. #endif
  7188. @@ -1916,12 +1916,12 @@
  7189. * Block interrupts because vortex_interrupt does a bare spin_lock()
  7190. */
  7191. unsigned long flags;
  7192. - local_irq_save(flags);
  7193. + local_irq_save_nort(flags);
  7194. if (vp->full_bus_master_tx)
  7195. boomerang_interrupt(dev->irq, dev);
  7196. else
  7197. vortex_interrupt(dev->irq, dev);
  7198. - local_irq_restore(flags);
  7199. + local_irq_restore_nort(flags);
  7200. }
  7201. }
  7202. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c linux-4.1.6/drivers/net/ethernet/atheros/atl1c/atl1c_main.c
  7203. --- linux-4.1.6.orig/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2015-08-17 05:52:51.000000000 +0200
  7204. +++ linux-4.1.6/drivers/net/ethernet/atheros/atl1c/atl1c_main.c 2015-09-08 23:49:06.086091361 +0200
  7205. @@ -2213,11 +2213,7 @@
  7206. }
  7207. tpd_req = atl1c_cal_tpd_req(skb);
  7208. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags)) {
  7209. - if (netif_msg_pktdata(adapter))
  7210. - dev_info(&adapter->pdev->dev, "tx locked\n");
  7211. - return NETDEV_TX_LOCKED;
  7212. - }
  7213. + spin_lock_irqsave(&adapter->tx_lock, flags);
  7214. if (atl1c_tpd_avail(adapter, type) < tpd_req) {
  7215. /* no enough descriptor, just stop queue */
  7216. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c linux-4.1.6/drivers/net/ethernet/atheros/atl1e/atl1e_main.c
  7217. --- linux-4.1.6.orig/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2015-08-17 05:52:51.000000000 +0200
  7218. +++ linux-4.1.6/drivers/net/ethernet/atheros/atl1e/atl1e_main.c 2015-09-08 23:49:06.086091361 +0200
  7219. @@ -1880,8 +1880,7 @@
  7220. return NETDEV_TX_OK;
  7221. }
  7222. tpd_req = atl1e_cal_tdp_req(skb);
  7223. - if (!spin_trylock_irqsave(&adapter->tx_lock, flags))
  7224. - return NETDEV_TX_LOCKED;
  7225. + spin_lock_irqsave(&adapter->tx_lock, flags);
  7226. if (atl1e_tpd_avail(adapter) < tpd_req) {
  7227. /* no enough descriptor, just stop queue */
  7228. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/chelsio/cxgb/sge.c linux-4.1.6/drivers/net/ethernet/chelsio/cxgb/sge.c
  7229. --- linux-4.1.6.orig/drivers/net/ethernet/chelsio/cxgb/sge.c 2015-08-17 05:52:51.000000000 +0200
  7230. +++ linux-4.1.6/drivers/net/ethernet/chelsio/cxgb/sge.c 2015-09-08 23:49:06.086091361 +0200
  7231. @@ -1664,8 +1664,7 @@
  7232. struct cmdQ *q = &sge->cmdQ[qid];
  7233. unsigned int credits, pidx, genbit, count, use_sched_skb = 0;
  7234. - if (!spin_trylock(&q->lock))
  7235. - return NETDEV_TX_LOCKED;
  7236. + spin_lock(&q->lock);
  7237. reclaim_completed_tx(sge, q);
  7238. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/freescale/gianfar.c linux-4.1.6/drivers/net/ethernet/freescale/gianfar.c
  7239. --- linux-4.1.6.orig/drivers/net/ethernet/freescale/gianfar.c 2015-08-17 05:52:51.000000000 +0200
  7240. +++ linux-4.1.6/drivers/net/ethernet/freescale/gianfar.c 2015-09-08 23:49:06.086091361 +0200
  7241. @@ -1540,7 +1540,7 @@
  7242. if (netif_running(ndev)) {
  7243. - local_irq_save(flags);
  7244. + local_irq_save_nort(flags);
  7245. lock_tx_qs(priv);
  7246. gfar_halt_nodisable(priv);
  7247. @@ -1556,7 +1556,7 @@
  7248. gfar_write(&regs->maccfg1, tempval);
  7249. unlock_tx_qs(priv);
  7250. - local_irq_restore(flags);
  7251. + local_irq_restore_nort(flags);
  7252. disable_napi(priv);
  7253. @@ -1598,7 +1598,7 @@
  7254. /* Disable Magic Packet mode, in case something
  7255. * else woke us up.
  7256. */
  7257. - local_irq_save(flags);
  7258. + local_irq_save_nort(flags);
  7259. lock_tx_qs(priv);
  7260. tempval = gfar_read(&regs->maccfg2);
  7261. @@ -1608,7 +1608,7 @@
  7262. gfar_start(priv);
  7263. unlock_tx_qs(priv);
  7264. - local_irq_restore(flags);
  7265. + local_irq_restore_nort(flags);
  7266. netif_device_attach(ndev);
  7267. @@ -3418,14 +3418,14 @@
  7268. dev->stats.tx_dropped++;
  7269. atomic64_inc(&priv->extra_stats.tx_underrun);
  7270. - local_irq_save(flags);
  7271. + local_irq_save_nort(flags);
  7272. lock_tx_qs(priv);
  7273. /* Reactivate the Tx Queues */
  7274. gfar_write(&regs->tstat, gfargrp->tstat);
  7275. unlock_tx_qs(priv);
  7276. - local_irq_restore(flags);
  7277. + local_irq_restore_nort(flags);
  7278. }
  7279. netif_dbg(priv, tx_err, dev, "Transmit Error\n");
  7280. }
  7281. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/neterion/s2io.c linux-4.1.6/drivers/net/ethernet/neterion/s2io.c
  7282. --- linux-4.1.6.orig/drivers/net/ethernet/neterion/s2io.c 2015-08-17 05:52:51.000000000 +0200
  7283. +++ linux-4.1.6/drivers/net/ethernet/neterion/s2io.c 2015-09-08 23:49:06.098090029 +0200
  7284. @@ -4084,12 +4084,7 @@
  7285. [skb->priority & (MAX_TX_FIFOS - 1)];
  7286. fifo = &mac_control->fifos[queue];
  7287. - if (do_spin_lock)
  7288. - spin_lock_irqsave(&fifo->tx_lock, flags);
  7289. - else {
  7290. - if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  7291. - return NETDEV_TX_LOCKED;
  7292. - }
  7293. + spin_lock_irqsave(&fifo->tx_lock, flags);
  7294. if (sp->config.multiq) {
  7295. if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
  7296. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c linux-4.1.6/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
  7297. --- linux-4.1.6.orig/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2015-08-17 05:52:51.000000000 +0200
  7298. +++ linux-4.1.6/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c 2015-09-08 23:49:06.302067412 +0200
  7299. @@ -2137,10 +2137,8 @@
  7300. struct pch_gbe_tx_ring *tx_ring = adapter->tx_ring;
  7301. unsigned long flags;
  7302. - if (!spin_trylock_irqsave(&tx_ring->tx_lock, flags)) {
  7303. - /* Collision - tell upper layer to requeue */
  7304. - return NETDEV_TX_LOCKED;
  7305. - }
  7306. + spin_lock_irqsave(&tx_ring->tx_lock, flags);
  7307. +
  7308. if (unlikely(!PCH_GBE_DESC_UNUSED(tx_ring))) {
  7309. netif_stop_queue(netdev);
  7310. spin_unlock_irqrestore(&tx_ring->tx_lock, flags);
  7311. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/realtek/8139too.c linux-4.1.6/drivers/net/ethernet/realtek/8139too.c
  7312. --- linux-4.1.6.orig/drivers/net/ethernet/realtek/8139too.c 2015-08-17 05:52:51.000000000 +0200
  7313. +++ linux-4.1.6/drivers/net/ethernet/realtek/8139too.c 2015-09-08 23:49:06.306066968 +0200
  7314. @@ -2229,7 +2229,7 @@
  7315. struct rtl8139_private *tp = netdev_priv(dev);
  7316. const int irq = tp->pci_dev->irq;
  7317. - disable_irq(irq);
  7318. + disable_irq_nosync(irq);
  7319. rtl8139_interrupt(irq, dev);
  7320. enable_irq(irq);
  7321. }
  7322. diff -Nur linux-4.1.6.orig/drivers/net/ethernet/tehuti/tehuti.c linux-4.1.6/drivers/net/ethernet/tehuti/tehuti.c
  7323. --- linux-4.1.6.orig/drivers/net/ethernet/tehuti/tehuti.c 2015-08-17 05:52:51.000000000 +0200
  7324. +++ linux-4.1.6/drivers/net/ethernet/tehuti/tehuti.c 2015-09-08 23:49:06.306066968 +0200
  7325. @@ -1629,13 +1629,8 @@
  7326. unsigned long flags;
  7327. ENTER;
  7328. - local_irq_save(flags);
  7329. - if (!spin_trylock(&priv->tx_lock)) {
  7330. - local_irq_restore(flags);
  7331. - DBG("%s[%s]: TX locked, returning NETDEV_TX_LOCKED\n",
  7332. - BDX_DRV_NAME, ndev->name);
  7333. - return NETDEV_TX_LOCKED;
  7334. - }
  7335. +
  7336. + spin_lock_irqsave(&priv->tx_lock, flags);
  7337. /* build tx descriptor */
  7338. BDX_ASSERT(f->m.wptr >= f->m.memsz); /* started with valid wptr */
  7339. diff -Nur linux-4.1.6.orig/drivers/net/rionet.c linux-4.1.6/drivers/net/rionet.c
  7340. --- linux-4.1.6.orig/drivers/net/rionet.c 2015-08-17 05:52:51.000000000 +0200
  7341. +++ linux-4.1.6/drivers/net/rionet.c 2015-09-08 23:49:06.306066968 +0200
  7342. @@ -174,11 +174,7 @@
  7343. unsigned long flags;
  7344. int add_num = 1;
  7345. - local_irq_save(flags);
  7346. - if (!spin_trylock(&rnet->tx_lock)) {
  7347. - local_irq_restore(flags);
  7348. - return NETDEV_TX_LOCKED;
  7349. - }
  7350. + spin_lock_irqsave(&rnet->tx_lock, flags);
  7351. if (is_multicast_ether_addr(eth->h_dest))
  7352. add_num = nets[rnet->mport->id].nact;
  7353. diff -Nur linux-4.1.6.orig/drivers/net/wireless/orinoco/orinoco_usb.c linux-4.1.6/drivers/net/wireless/orinoco/orinoco_usb.c
  7354. --- linux-4.1.6.orig/drivers/net/wireless/orinoco/orinoco_usb.c 2015-08-17 05:52:51.000000000 +0200
  7355. +++ linux-4.1.6/drivers/net/wireless/orinoco/orinoco_usb.c 2015-09-08 23:49:06.306066968 +0200
  7356. @@ -697,7 +697,7 @@
  7357. while (!ctx->done.done && msecs--)
  7358. udelay(1000);
  7359. } else {
  7360. - wait_event_interruptible(ctx->done.wait,
  7361. + swait_event_interruptible(ctx->done.wait,
  7362. ctx->done.done);
  7363. }
  7364. break;
  7365. diff -Nur linux-4.1.6.orig/drivers/pci/access.c linux-4.1.6/drivers/pci/access.c
  7366. --- linux-4.1.6.orig/drivers/pci/access.c 2015-08-17 05:52:51.000000000 +0200
  7367. +++ linux-4.1.6/drivers/pci/access.c 2015-09-08 23:49:06.310066523 +0200
  7368. @@ -521,7 +521,7 @@
  7369. WARN_ON(!dev->block_cfg_access);
  7370. dev->block_cfg_access = 0;
  7371. - wake_up_all(&pci_cfg_wait);
  7372. + wake_up_all_locked(&pci_cfg_wait);
  7373. raw_spin_unlock_irqrestore(&pci_lock, flags);
  7374. }
  7375. EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
  7376. diff -Nur linux-4.1.6.orig/drivers/scsi/fcoe/fcoe.c linux-4.1.6/drivers/scsi/fcoe/fcoe.c
  7377. --- linux-4.1.6.orig/drivers/scsi/fcoe/fcoe.c 2015-08-17 05:52:51.000000000 +0200
  7378. +++ linux-4.1.6/drivers/scsi/fcoe/fcoe.c 2015-09-08 23:49:06.314066079 +0200
  7379. @@ -1287,7 +1287,7 @@
  7380. struct sk_buff *skb;
  7381. #ifdef CONFIG_SMP
  7382. struct fcoe_percpu_s *p0;
  7383. - unsigned targ_cpu = get_cpu();
  7384. + unsigned targ_cpu = get_cpu_light();
  7385. #endif /* CONFIG_SMP */
  7386. FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
  7387. @@ -1343,7 +1343,7 @@
  7388. kfree_skb(skb);
  7389. spin_unlock_bh(&p->fcoe_rx_list.lock);
  7390. }
  7391. - put_cpu();
  7392. + put_cpu_light();
  7393. #else
  7394. /*
  7395. * This a non-SMP scenario where the singular Rx thread is
  7396. @@ -1567,11 +1567,11 @@
  7397. static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen)
  7398. {
  7399. struct fcoe_percpu_s *fps;
  7400. - int rc;
  7401. + int rc, cpu = get_cpu_light();
  7402. - fps = &get_cpu_var(fcoe_percpu);
  7403. + fps = &per_cpu(fcoe_percpu, cpu);
  7404. rc = fcoe_get_paged_crc_eof(skb, tlen, fps);
  7405. - put_cpu_var(fcoe_percpu);
  7406. + put_cpu_light();
  7407. return rc;
  7408. }
  7409. @@ -1767,11 +1767,11 @@
  7410. return 0;
  7411. }
  7412. - stats = per_cpu_ptr(lport->stats, get_cpu());
  7413. + stats = per_cpu_ptr(lport->stats, get_cpu_light());
  7414. stats->InvalidCRCCount++;
  7415. if (stats->InvalidCRCCount < 5)
  7416. printk(KERN_WARNING "fcoe: dropping frame with CRC error\n");
  7417. - put_cpu();
  7418. + put_cpu_light();
  7419. return -EINVAL;
  7420. }
  7421. @@ -1847,13 +1847,13 @@
  7422. goto drop;
  7423. if (!fcoe_filter_frames(lport, fp)) {
  7424. - put_cpu();
  7425. + put_cpu_light();
  7426. fc_exch_recv(lport, fp);
  7427. return;
  7428. }
  7429. drop:
  7430. stats->ErrorFrames++;
  7431. - put_cpu();
  7432. + put_cpu_light();
  7433. kfree_skb(skb);
  7434. }
  7435. diff -Nur linux-4.1.6.orig/drivers/scsi/fcoe/fcoe_ctlr.c linux-4.1.6/drivers/scsi/fcoe/fcoe_ctlr.c
  7436. --- linux-4.1.6.orig/drivers/scsi/fcoe/fcoe_ctlr.c 2015-08-17 05:52:51.000000000 +0200
  7437. +++ linux-4.1.6/drivers/scsi/fcoe/fcoe_ctlr.c 2015-09-08 23:49:06.314066079 +0200
  7438. @@ -831,7 +831,7 @@
  7439. INIT_LIST_HEAD(&del_list);
  7440. - stats = per_cpu_ptr(fip->lp->stats, get_cpu());
  7441. + stats = per_cpu_ptr(fip->lp->stats, get_cpu_light());
  7442. list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
  7443. deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2;
  7444. @@ -867,7 +867,7 @@
  7445. sel_time = fcf->time;
  7446. }
  7447. }
  7448. - put_cpu();
  7449. + put_cpu_light();
  7450. list_for_each_entry_safe(fcf, next, &del_list, list) {
  7451. /* Removes fcf from current list */
  7452. diff -Nur linux-4.1.6.orig/drivers/scsi/libfc/fc_exch.c linux-4.1.6/drivers/scsi/libfc/fc_exch.c
  7453. --- linux-4.1.6.orig/drivers/scsi/libfc/fc_exch.c 2015-08-17 05:52:51.000000000 +0200
  7454. +++ linux-4.1.6/drivers/scsi/libfc/fc_exch.c 2015-09-08 23:49:06.314066079 +0200
  7455. @@ -816,10 +816,10 @@
  7456. }
  7457. memset(ep, 0, sizeof(*ep));
  7458. - cpu = get_cpu();
  7459. + cpu = get_cpu_light();
  7460. pool = per_cpu_ptr(mp->pool, cpu);
  7461. spin_lock_bh(&pool->lock);
  7462. - put_cpu();
  7463. + put_cpu_light();
  7464. /* peek cache of free slot */
  7465. if (pool->left != FC_XID_UNKNOWN) {
  7466. diff -Nur linux-4.1.6.orig/drivers/scsi/libsas/sas_ata.c linux-4.1.6/drivers/scsi/libsas/sas_ata.c
  7467. --- linux-4.1.6.orig/drivers/scsi/libsas/sas_ata.c 2015-08-17 05:52:51.000000000 +0200
  7468. +++ linux-4.1.6/drivers/scsi/libsas/sas_ata.c 2015-09-08 23:49:06.314066079 +0200
  7469. @@ -190,7 +190,7 @@
  7470. /* TODO: audit callers to ensure they are ready for qc_issue to
  7471. * unconditionally re-enable interrupts
  7472. */
  7473. - local_irq_save(flags);
  7474. + local_irq_save_nort(flags);
  7475. spin_unlock(ap->lock);
  7476. /* If the device fell off, no sense in issuing commands */
  7477. @@ -255,7 +255,7 @@
  7478. out:
  7479. spin_lock(ap->lock);
  7480. - local_irq_restore(flags);
  7481. + local_irq_restore_nort(flags);
  7482. return ret;
  7483. }
  7484. diff -Nur linux-4.1.6.orig/drivers/scsi/qla2xxx/qla_inline.h linux-4.1.6/drivers/scsi/qla2xxx/qla_inline.h
  7485. --- linux-4.1.6.orig/drivers/scsi/qla2xxx/qla_inline.h 2015-08-17 05:52:51.000000000 +0200
  7486. +++ linux-4.1.6/drivers/scsi/qla2xxx/qla_inline.h 2015-09-08 23:49:06.314066079 +0200
  7487. @@ -59,12 +59,12 @@
  7488. {
  7489. unsigned long flags;
  7490. struct qla_hw_data *ha = rsp->hw;
  7491. - local_irq_save(flags);
  7492. + local_irq_save_nort(flags);
  7493. if (IS_P3P_TYPE(ha))
  7494. qla82xx_poll(0, rsp);
  7495. else
  7496. ha->isp_ops->intr_handler(0, rsp);
  7497. - local_irq_restore(flags);
  7498. + local_irq_restore_nort(flags);
  7499. }
  7500. static inline uint8_t *
  7501. diff -Nur linux-4.1.6.orig/drivers/thermal/x86_pkg_temp_thermal.c linux-4.1.6/drivers/thermal/x86_pkg_temp_thermal.c
  7502. --- linux-4.1.6.orig/drivers/thermal/x86_pkg_temp_thermal.c 2015-08-17 05:52:51.000000000 +0200
  7503. +++ linux-4.1.6/drivers/thermal/x86_pkg_temp_thermal.c 2015-09-08 23:49:06.314066079 +0200
  7504. @@ -29,6 +29,7 @@
  7505. #include <linux/pm.h>
  7506. #include <linux/thermal.h>
  7507. #include <linux/debugfs.h>
  7508. +#include <linux/work-simple.h>
  7509. #include <asm/cpu_device_id.h>
  7510. #include <asm/mce.h>
  7511. @@ -352,7 +353,7 @@
  7512. }
  7513. }
  7514. -static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  7515. +static void platform_thermal_notify_work(struct swork_event *event)
  7516. {
  7517. unsigned long flags;
  7518. int cpu = smp_processor_id();
  7519. @@ -369,7 +370,7 @@
  7520. pkg_work_scheduled[phy_id]) {
  7521. disable_pkg_thres_interrupt();
  7522. spin_unlock_irqrestore(&pkg_work_lock, flags);
  7523. - return -EINVAL;
  7524. + return;
  7525. }
  7526. pkg_work_scheduled[phy_id] = 1;
  7527. spin_unlock_irqrestore(&pkg_work_lock, flags);
  7528. @@ -378,9 +379,48 @@
  7529. schedule_delayed_work_on(cpu,
  7530. &per_cpu(pkg_temp_thermal_threshold_work, cpu),
  7531. msecs_to_jiffies(notify_delay_ms));
  7532. +}
  7533. +
  7534. +#ifdef CONFIG_PREEMPT_RT_FULL
  7535. +static struct swork_event notify_work;
  7536. +
  7537. +static int thermal_notify_work_init(void)
  7538. +{
  7539. + int err;
  7540. +
  7541. + err = swork_get();
  7542. + if (err)
  7543. + return err;
  7544. +
  7545. + INIT_SWORK(&notify_work, platform_thermal_notify_work);
  7546. return 0;
  7547. }
  7548. +static void thermal_notify_work_cleanup(void)
  7549. +{
  7550. + swork_put();
  7551. +}
  7552. +
  7553. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  7554. +{
  7555. + swork_queue(&notify_work);
  7556. + return 0;
  7557. +}
  7558. +
  7559. +#else /* !CONFIG_PREEMPT_RT_FULL */
  7560. +
  7561. +static int thermal_notify_work_init(void) { return 0; }
  7562. +
  7563. +static void thermal_notify_work_cleanup(void) { }
  7564. +
  7565. +static int pkg_temp_thermal_platform_thermal_notify(__u64 msr_val)
  7566. +{
  7567. + platform_thermal_notify_work(NULL);
  7568. +
  7569. + return 0;
  7570. +}
  7571. +#endif /* CONFIG_PREEMPT_RT_FULL */
  7572. +
  7573. static int find_siblings_cpu(int cpu)
  7574. {
  7575. int i;
  7576. @@ -584,6 +624,9 @@
  7577. if (!x86_match_cpu(pkg_temp_thermal_ids))
  7578. return -ENODEV;
  7579. + if (!thermal_notify_work_init())
  7580. + return -ENODEV;
  7581. +
  7582. spin_lock_init(&pkg_work_lock);
  7583. platform_thermal_package_notify =
  7584. pkg_temp_thermal_platform_thermal_notify;
  7585. @@ -608,7 +651,7 @@
  7586. kfree(pkg_work_scheduled);
  7587. platform_thermal_package_notify = NULL;
  7588. platform_thermal_package_rate_control = NULL;
  7589. -
  7590. + thermal_notify_work_cleanup();
  7591. return -ENODEV;
  7592. }
  7593. @@ -633,6 +676,7 @@
  7594. mutex_unlock(&phy_dev_list_mutex);
  7595. platform_thermal_package_notify = NULL;
  7596. platform_thermal_package_rate_control = NULL;
  7597. + thermal_notify_work_cleanup();
  7598. for_each_online_cpu(i)
  7599. cancel_delayed_work_sync(
  7600. &per_cpu(pkg_temp_thermal_threshold_work, i));
  7601. diff -Nur linux-4.1.6.orig/drivers/tty/serial/8250/8250_core.c linux-4.1.6/drivers/tty/serial/8250/8250_core.c
  7602. --- linux-4.1.6.orig/drivers/tty/serial/8250/8250_core.c 2015-08-17 05:52:51.000000000 +0200
  7603. +++ linux-4.1.6/drivers/tty/serial/8250/8250_core.c 2015-09-08 23:49:06.314066079 +0200
  7604. @@ -36,6 +36,7 @@
  7605. #include <linux/nmi.h>
  7606. #include <linux/mutex.h>
  7607. #include <linux/slab.h>
  7608. +#include <linux/kdb.h>
  7609. #include <linux/uaccess.h>
  7610. #include <linux/pm_runtime.h>
  7611. #ifdef CONFIG_SPARC
  7612. @@ -80,7 +81,16 @@
  7613. #define DEBUG_INTR(fmt...) do { } while (0)
  7614. #endif
  7615. -#define PASS_LIMIT 512
  7616. +/*
  7617. + * On -rt we can have a more delays, and legitimately
  7618. + * so - so don't drop work spuriously and spam the
  7619. + * syslog:
  7620. + */
  7621. +#ifdef CONFIG_PREEMPT_RT_FULL
  7622. +# define PASS_LIMIT 1000000
  7623. +#else
  7624. +# define PASS_LIMIT 512
  7625. +#endif
  7626. #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
  7627. @@ -3364,7 +3374,7 @@
  7628. if (port->sysrq)
  7629. locked = 0;
  7630. - else if (oops_in_progress)
  7631. + else if (oops_in_progress || in_kdb_printk())
  7632. locked = spin_trylock_irqsave(&port->lock, flags);
  7633. else
  7634. spin_lock_irqsave(&port->lock, flags);
  7635. diff -Nur linux-4.1.6.orig/drivers/tty/serial/amba-pl011.c linux-4.1.6/drivers/tty/serial/amba-pl011.c
  7636. --- linux-4.1.6.orig/drivers/tty/serial/amba-pl011.c 2015-08-17 05:52:51.000000000 +0200
  7637. +++ linux-4.1.6/drivers/tty/serial/amba-pl011.c 2015-09-08 23:49:06.314066079 +0200
  7638. @@ -2000,13 +2000,19 @@
  7639. clk_enable(uap->clk);
  7640. - local_irq_save(flags);
  7641. + /*
  7642. + * local_irq_save(flags);
  7643. + *
  7644. + * This local_irq_save() is nonsense. If we come in via sysrq
  7645. + * handling then interrupts are already disabled. Aside of
  7646. + * that the port.sysrq check is racy on SMP regardless.
  7647. + */
  7648. if (uap->port.sysrq)
  7649. locked = 0;
  7650. else if (oops_in_progress)
  7651. - locked = spin_trylock(&uap->port.lock);
  7652. + locked = spin_trylock_irqsave(&uap->port.lock, flags);
  7653. else
  7654. - spin_lock(&uap->port.lock);
  7655. + spin_lock_irqsave(&uap->port.lock, flags);
  7656. /*
  7657. * First save the CR then disable the interrupts
  7658. @@ -2028,8 +2034,7 @@
  7659. writew(old_cr, uap->port.membase + UART011_CR);
  7660. if (locked)
  7661. - spin_unlock(&uap->port.lock);
  7662. - local_irq_restore(flags);
  7663. + spin_unlock_irqrestore(&uap->port.lock, flags);
  7664. clk_disable(uap->clk);
  7665. }
  7666. diff -Nur linux-4.1.6.orig/drivers/tty/serial/omap-serial.c linux-4.1.6/drivers/tty/serial/omap-serial.c
  7667. --- linux-4.1.6.orig/drivers/tty/serial/omap-serial.c 2015-08-17 05:52:51.000000000 +0200
  7668. +++ linux-4.1.6/drivers/tty/serial/omap-serial.c 2015-09-08 23:49:06.314066079 +0200
  7669. @@ -1282,13 +1282,10 @@
  7670. pm_runtime_get_sync(up->dev);
  7671. - local_irq_save(flags);
  7672. - if (up->port.sysrq)
  7673. - locked = 0;
  7674. - else if (oops_in_progress)
  7675. - locked = spin_trylock(&up->port.lock);
  7676. + if (up->port.sysrq || oops_in_progress)
  7677. + locked = spin_trylock_irqsave(&up->port.lock, flags);
  7678. else
  7679. - spin_lock(&up->port.lock);
  7680. + spin_lock_irqsave(&up->port.lock, flags);
  7681. /*
  7682. * First save the IER then disable the interrupts
  7683. @@ -1317,8 +1314,7 @@
  7684. pm_runtime_mark_last_busy(up->dev);
  7685. pm_runtime_put_autosuspend(up->dev);
  7686. if (locked)
  7687. - spin_unlock(&up->port.lock);
  7688. - local_irq_restore(flags);
  7689. + spin_unlock_irqrestore(&up->port.lock, flags);
  7690. }
  7691. static int __init
  7692. diff -Nur linux-4.1.6.orig/drivers/usb/core/hcd.c linux-4.1.6/drivers/usb/core/hcd.c
  7693. --- linux-4.1.6.orig/drivers/usb/core/hcd.c 2015-08-17 05:52:51.000000000 +0200
  7694. +++ linux-4.1.6/drivers/usb/core/hcd.c 2015-09-08 23:49:06.314066079 +0200
  7695. @@ -1684,9 +1684,9 @@
  7696. * and no one may trigger the above deadlock situation when
  7697. * running complete() in tasklet.
  7698. */
  7699. - local_irq_save(flags);
  7700. + local_irq_save_nort(flags);
  7701. urb->complete(urb);
  7702. - local_irq_restore(flags);
  7703. + local_irq_restore_nort(flags);
  7704. usb_anchor_resume_wakeups(anchor);
  7705. atomic_dec(&urb->use_count);
  7706. diff -Nur linux-4.1.6.orig/drivers/usb/gadget/function/f_fs.c linux-4.1.6/drivers/usb/gadget/function/f_fs.c
  7707. --- linux-4.1.6.orig/drivers/usb/gadget/function/f_fs.c 2015-08-17 05:52:51.000000000 +0200
  7708. +++ linux-4.1.6/drivers/usb/gadget/function/f_fs.c 2015-09-08 23:49:06.318065636 +0200
  7709. @@ -1405,7 +1405,7 @@
  7710. pr_info("%s(): freeing\n", __func__);
  7711. ffs_data_clear(ffs);
  7712. BUG_ON(waitqueue_active(&ffs->ev.waitq) ||
  7713. - waitqueue_active(&ffs->ep0req_completion.wait));
  7714. + swaitqueue_active(&ffs->ep0req_completion.wait));
  7715. kfree(ffs->dev_name);
  7716. kfree(ffs);
  7717. }
  7718. diff -Nur linux-4.1.6.orig/drivers/usb/gadget/legacy/inode.c linux-4.1.6/drivers/usb/gadget/legacy/inode.c
  7719. --- linux-4.1.6.orig/drivers/usb/gadget/legacy/inode.c 2015-08-17 05:52:51.000000000 +0200
  7720. +++ linux-4.1.6/drivers/usb/gadget/legacy/inode.c 2015-09-08 23:49:06.318065636 +0200
  7721. @@ -345,7 +345,7 @@
  7722. spin_unlock_irq (&epdata->dev->lock);
  7723. if (likely (value == 0)) {
  7724. - value = wait_event_interruptible (done.wait, done.done);
  7725. + value = swait_event_interruptible (done.wait, done.done);
  7726. if (value != 0) {
  7727. spin_lock_irq (&epdata->dev->lock);
  7728. if (likely (epdata->ep != NULL)) {
  7729. @@ -354,7 +354,7 @@
  7730. usb_ep_dequeue (epdata->ep, epdata->req);
  7731. spin_unlock_irq (&epdata->dev->lock);
  7732. - wait_event (done.wait, done.done);
  7733. + swait_event (done.wait, done.done);
  7734. if (epdata->status == -ECONNRESET)
  7735. epdata->status = -EINTR;
  7736. } else {
  7737. diff -Nur linux-4.1.6.orig/fs/aio.c linux-4.1.6/fs/aio.c
  7738. --- linux-4.1.6.orig/fs/aio.c 2015-08-17 05:52:51.000000000 +0200
  7739. +++ linux-4.1.6/fs/aio.c 2015-09-08 23:49:06.318065636 +0200
  7740. @@ -40,6 +40,7 @@
  7741. #include <linux/ramfs.h>
  7742. #include <linux/percpu-refcount.h>
  7743. #include <linux/mount.h>
  7744. +#include <linux/work-simple.h>
  7745. #include <asm/kmap_types.h>
  7746. #include <asm/uaccess.h>
  7747. @@ -115,7 +116,7 @@
  7748. struct page **ring_pages;
  7749. long nr_pages;
  7750. - struct work_struct free_work;
  7751. + struct swork_event free_work;
  7752. /*
  7753. * signals when all in-flight requests are done
  7754. @@ -253,6 +254,7 @@
  7755. .mount = aio_mount,
  7756. .kill_sb = kill_anon_super,
  7757. };
  7758. + BUG_ON(swork_get());
  7759. aio_mnt = kern_mount(&aio_fs);
  7760. if (IS_ERR(aio_mnt))
  7761. panic("Failed to create aio fs mount.");
  7762. @@ -559,9 +561,9 @@
  7763. return cancel(&kiocb->common);
  7764. }
  7765. -static void free_ioctx(struct work_struct *work)
  7766. +static void free_ioctx(struct swork_event *sev)
  7767. {
  7768. - struct kioctx *ctx = container_of(work, struct kioctx, free_work);
  7769. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  7770. pr_debug("freeing %p\n", ctx);
  7771. @@ -580,8 +582,8 @@
  7772. if (ctx->rq_wait && atomic_dec_and_test(&ctx->rq_wait->count))
  7773. complete(&ctx->rq_wait->comp);
  7774. - INIT_WORK(&ctx->free_work, free_ioctx);
  7775. - schedule_work(&ctx->free_work);
  7776. + INIT_SWORK(&ctx->free_work, free_ioctx);
  7777. + swork_queue(&ctx->free_work);
  7778. }
  7779. /*
  7780. @@ -589,9 +591,9 @@
  7781. * and ctx->users has dropped to 0, so we know no more kiocbs can be submitted -
  7782. * now it's safe to cancel any that need to be.
  7783. */
  7784. -static void free_ioctx_users(struct percpu_ref *ref)
  7785. +static void free_ioctx_users_work(struct swork_event *sev)
  7786. {
  7787. - struct kioctx *ctx = container_of(ref, struct kioctx, users);
  7788. + struct kioctx *ctx = container_of(sev, struct kioctx, free_work);
  7789. struct aio_kiocb *req;
  7790. spin_lock_irq(&ctx->ctx_lock);
  7791. @@ -610,6 +612,14 @@
  7792. percpu_ref_put(&ctx->reqs);
  7793. }
  7794. +static void free_ioctx_users(struct percpu_ref *ref)
  7795. +{
  7796. + struct kioctx *ctx = container_of(ref, struct kioctx, users);
  7797. +
  7798. + INIT_SWORK(&ctx->free_work, free_ioctx_users_work);
  7799. + swork_queue(&ctx->free_work);
  7800. +}
  7801. +
  7802. static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm)
  7803. {
  7804. unsigned i, new_nr;
  7805. diff -Nur linux-4.1.6.orig/fs/autofs4/autofs_i.h linux-4.1.6/fs/autofs4/autofs_i.h
  7806. --- linux-4.1.6.orig/fs/autofs4/autofs_i.h 2015-08-17 05:52:51.000000000 +0200
  7807. +++ linux-4.1.6/fs/autofs4/autofs_i.h 2015-09-08 23:49:06.318065636 +0200
  7808. @@ -34,6 +34,7 @@
  7809. #include <linux/sched.h>
  7810. #include <linux/mount.h>
  7811. #include <linux/namei.h>
  7812. +#include <linux/delay.h>
  7813. #include <asm/current.h>
  7814. #include <asm/uaccess.h>
  7815. diff -Nur linux-4.1.6.orig/fs/autofs4/expire.c linux-4.1.6/fs/autofs4/expire.c
  7816. --- linux-4.1.6.orig/fs/autofs4/expire.c 2015-08-17 05:52:51.000000000 +0200
  7817. +++ linux-4.1.6/fs/autofs4/expire.c 2015-09-08 23:49:06.318065636 +0200
  7818. @@ -150,7 +150,7 @@
  7819. parent = p->d_parent;
  7820. if (!spin_trylock(&parent->d_lock)) {
  7821. spin_unlock(&p->d_lock);
  7822. - cpu_relax();
  7823. + cpu_chill();
  7824. goto relock;
  7825. }
  7826. spin_unlock(&p->d_lock);
  7827. diff -Nur linux-4.1.6.orig/fs/buffer.c linux-4.1.6/fs/buffer.c
  7828. --- linux-4.1.6.orig/fs/buffer.c 2015-08-17 05:52:51.000000000 +0200
  7829. +++ linux-4.1.6/fs/buffer.c 2015-09-08 23:49:06.318065636 +0200
  7830. @@ -301,8 +301,7 @@
  7831. * decide that the page is now completely done.
  7832. */
  7833. first = page_buffers(page);
  7834. - local_irq_save(flags);
  7835. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  7836. + flags = bh_uptodate_lock_irqsave(first);
  7837. clear_buffer_async_read(bh);
  7838. unlock_buffer(bh);
  7839. tmp = bh;
  7840. @@ -315,8 +314,7 @@
  7841. }
  7842. tmp = tmp->b_this_page;
  7843. } while (tmp != bh);
  7844. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  7845. - local_irq_restore(flags);
  7846. + bh_uptodate_unlock_irqrestore(first, flags);
  7847. /*
  7848. * If none of the buffers had errors and they are all
  7849. @@ -328,9 +326,7 @@
  7850. return;
  7851. still_busy:
  7852. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  7853. - local_irq_restore(flags);
  7854. - return;
  7855. + bh_uptodate_unlock_irqrestore(first, flags);
  7856. }
  7857. /*
  7858. @@ -358,8 +354,7 @@
  7859. }
  7860. first = page_buffers(page);
  7861. - local_irq_save(flags);
  7862. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  7863. + flags = bh_uptodate_lock_irqsave(first);
  7864. clear_buffer_async_write(bh);
  7865. unlock_buffer(bh);
  7866. @@ -371,15 +366,12 @@
  7867. }
  7868. tmp = tmp->b_this_page;
  7869. }
  7870. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  7871. - local_irq_restore(flags);
  7872. + bh_uptodate_unlock_irqrestore(first, flags);
  7873. end_page_writeback(page);
  7874. return;
  7875. still_busy:
  7876. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  7877. - local_irq_restore(flags);
  7878. - return;
  7879. + bh_uptodate_unlock_irqrestore(first, flags);
  7880. }
  7881. EXPORT_SYMBOL(end_buffer_async_write);
  7882. @@ -3325,6 +3317,7 @@
  7883. struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
  7884. if (ret) {
  7885. INIT_LIST_HEAD(&ret->b_assoc_buffers);
  7886. + buffer_head_init_locks(ret);
  7887. preempt_disable();
  7888. __this_cpu_inc(bh_accounting.nr);
  7889. recalc_bh_state();
  7890. diff -Nur linux-4.1.6.orig/fs/dcache.c linux-4.1.6/fs/dcache.c
  7891. --- linux-4.1.6.orig/fs/dcache.c 2015-08-17 05:52:51.000000000 +0200
  7892. +++ linux-4.1.6/fs/dcache.c 2015-09-08 23:49:06.318065636 +0200
  7893. @@ -19,6 +19,7 @@
  7894. #include <linux/mm.h>
  7895. #include <linux/fs.h>
  7896. #include <linux/fsnotify.h>
  7897. +#include <linux/delay.h>
  7898. #include <linux/slab.h>
  7899. #include <linux/init.h>
  7900. #include <linux/hash.h>
  7901. @@ -589,7 +590,7 @@
  7902. failed:
  7903. spin_unlock(&dentry->d_lock);
  7904. - cpu_relax();
  7905. + cpu_chill();
  7906. return dentry; /* try again with same dentry */
  7907. }
  7908. @@ -2395,7 +2396,7 @@
  7909. if (dentry->d_lockref.count == 1) {
  7910. if (!spin_trylock(&inode->i_lock)) {
  7911. spin_unlock(&dentry->d_lock);
  7912. - cpu_relax();
  7913. + cpu_chill();
  7914. goto again;
  7915. }
  7916. dentry->d_flags &= ~DCACHE_CANT_MOUNT;
  7917. diff -Nur linux-4.1.6.orig/fs/eventpoll.c linux-4.1.6/fs/eventpoll.c
  7918. --- linux-4.1.6.orig/fs/eventpoll.c 2015-08-17 05:52:51.000000000 +0200
  7919. +++ linux-4.1.6/fs/eventpoll.c 2015-09-08 23:49:06.318065636 +0200
  7920. @@ -505,12 +505,12 @@
  7921. */
  7922. static void ep_poll_safewake(wait_queue_head_t *wq)
  7923. {
  7924. - int this_cpu = get_cpu();
  7925. + int this_cpu = get_cpu_light();
  7926. ep_call_nested(&poll_safewake_ncalls, EP_MAX_NESTS,
  7927. ep_poll_wakeup_proc, NULL, wq, (void *) (long) this_cpu);
  7928. - put_cpu();
  7929. + put_cpu_light();
  7930. }
  7931. static void ep_remove_wait_queue(struct eppoll_entry *pwq)
  7932. diff -Nur linux-4.1.6.orig/fs/exec.c linux-4.1.6/fs/exec.c
  7933. --- linux-4.1.6.orig/fs/exec.c 2015-08-17 05:52:51.000000000 +0200
  7934. +++ linux-4.1.6/fs/exec.c 2015-09-08 23:49:06.318065636 +0200
  7935. @@ -859,12 +859,14 @@
  7936. }
  7937. }
  7938. task_lock(tsk);
  7939. + preempt_disable_rt();
  7940. active_mm = tsk->active_mm;
  7941. tsk->mm = mm;
  7942. tsk->active_mm = mm;
  7943. activate_mm(active_mm, mm);
  7944. tsk->mm->vmacache_seqnum = 0;
  7945. vmacache_flush(tsk);
  7946. + preempt_enable_rt();
  7947. task_unlock(tsk);
  7948. if (old_mm) {
  7949. up_read(&old_mm->mmap_sem);
  7950. diff -Nur linux-4.1.6.orig/fs/jbd/checkpoint.c linux-4.1.6/fs/jbd/checkpoint.c
  7951. --- linux-4.1.6.orig/fs/jbd/checkpoint.c 2015-08-17 05:52:51.000000000 +0200
  7952. +++ linux-4.1.6/fs/jbd/checkpoint.c 2015-09-08 23:49:06.318065636 +0200
  7953. @@ -129,6 +129,8 @@
  7954. if (journal->j_flags & JFS_ABORT)
  7955. return;
  7956. spin_unlock(&journal->j_state_lock);
  7957. + if (current->plug)
  7958. + io_schedule();
  7959. mutex_lock(&journal->j_checkpoint_mutex);
  7960. /*
  7961. diff -Nur linux-4.1.6.orig/fs/jbd2/checkpoint.c linux-4.1.6/fs/jbd2/checkpoint.c
  7962. --- linux-4.1.6.orig/fs/jbd2/checkpoint.c 2015-08-17 05:52:51.000000000 +0200
  7963. +++ linux-4.1.6/fs/jbd2/checkpoint.c 2015-09-08 23:49:06.322065194 +0200
  7964. @@ -116,6 +116,8 @@
  7965. nblocks = jbd2_space_needed(journal);
  7966. while (jbd2_log_space_left(journal) < nblocks) {
  7967. write_unlock(&journal->j_state_lock);
  7968. + if (current->plug)
  7969. + io_schedule();
  7970. mutex_lock(&journal->j_checkpoint_mutex);
  7971. /*
  7972. diff -Nur linux-4.1.6.orig/fs/namespace.c linux-4.1.6/fs/namespace.c
  7973. --- linux-4.1.6.orig/fs/namespace.c 2015-08-17 05:52:51.000000000 +0200
  7974. +++ linux-4.1.6/fs/namespace.c 2015-09-08 23:49:06.322065194 +0200
  7975. @@ -14,6 +14,7 @@
  7976. #include <linux/mnt_namespace.h>
  7977. #include <linux/user_namespace.h>
  7978. #include <linux/namei.h>
  7979. +#include <linux/delay.h>
  7980. #include <linux/security.h>
  7981. #include <linux/idr.h>
  7982. #include <linux/init.h> /* init_rootfs */
  7983. @@ -353,8 +354,11 @@
  7984. * incremented count after it has set MNT_WRITE_HOLD.
  7985. */
  7986. smp_mb();
  7987. - while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD)
  7988. - cpu_relax();
  7989. + while (ACCESS_ONCE(mnt->mnt.mnt_flags) & MNT_WRITE_HOLD) {
  7990. + preempt_enable();
  7991. + cpu_chill();
  7992. + preempt_disable();
  7993. + }
  7994. /*
  7995. * After the slowpath clears MNT_WRITE_HOLD, mnt_is_readonly will
  7996. * be set to match its requirements. So we must not load that until
  7997. diff -Nur linux-4.1.6.orig/fs/ntfs/aops.c linux-4.1.6/fs/ntfs/aops.c
  7998. --- linux-4.1.6.orig/fs/ntfs/aops.c 2015-08-17 05:52:51.000000000 +0200
  7999. +++ linux-4.1.6/fs/ntfs/aops.c 2015-09-08 23:49:06.322065194 +0200
  8000. @@ -107,8 +107,7 @@
  8001. "0x%llx.", (unsigned long long)bh->b_blocknr);
  8002. }
  8003. first = page_buffers(page);
  8004. - local_irq_save(flags);
  8005. - bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
  8006. + flags = bh_uptodate_lock_irqsave(first);
  8007. clear_buffer_async_read(bh);
  8008. unlock_buffer(bh);
  8009. tmp = bh;
  8010. @@ -123,8 +122,7 @@
  8011. }
  8012. tmp = tmp->b_this_page;
  8013. } while (tmp != bh);
  8014. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8015. - local_irq_restore(flags);
  8016. + bh_uptodate_unlock_irqrestore(first, flags);
  8017. /*
  8018. * If none of the buffers had errors then we can set the page uptodate,
  8019. * but we first have to perform the post read mst fixups, if the
  8020. @@ -145,13 +143,13 @@
  8021. recs = PAGE_CACHE_SIZE / rec_size;
  8022. /* Should have been verified before we got here... */
  8023. BUG_ON(!recs);
  8024. - local_irq_save(flags);
  8025. + local_irq_save_nort(flags);
  8026. kaddr = kmap_atomic(page);
  8027. for (i = 0; i < recs; i++)
  8028. post_read_mst_fixup((NTFS_RECORD*)(kaddr +
  8029. i * rec_size), rec_size);
  8030. kunmap_atomic(kaddr);
  8031. - local_irq_restore(flags);
  8032. + local_irq_restore_nort(flags);
  8033. flush_dcache_page(page);
  8034. if (likely(page_uptodate && !PageError(page)))
  8035. SetPageUptodate(page);
  8036. @@ -159,9 +157,7 @@
  8037. unlock_page(page);
  8038. return;
  8039. still_busy:
  8040. - bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
  8041. - local_irq_restore(flags);
  8042. - return;
  8043. + bh_uptodate_unlock_irqrestore(first, flags);
  8044. }
  8045. /**
  8046. diff -Nur linux-4.1.6.orig/fs/timerfd.c linux-4.1.6/fs/timerfd.c
  8047. --- linux-4.1.6.orig/fs/timerfd.c 2015-08-17 05:52:51.000000000 +0200
  8048. +++ linux-4.1.6/fs/timerfd.c 2015-09-08 23:49:06.322065194 +0200
  8049. @@ -450,7 +450,10 @@
  8050. break;
  8051. }
  8052. spin_unlock_irq(&ctx->wqh.lock);
  8053. - cpu_relax();
  8054. + if (isalarm(ctx))
  8055. + hrtimer_wait_for_timer(&ctx->t.alarm.timer);
  8056. + else
  8057. + hrtimer_wait_for_timer(&ctx->t.tmr);
  8058. }
  8059. /*
  8060. diff -Nur linux-4.1.6.orig/include/acpi/platform/aclinux.h linux-4.1.6/include/acpi/platform/aclinux.h
  8061. --- linux-4.1.6.orig/include/acpi/platform/aclinux.h 2015-08-17 05:52:51.000000000 +0200
  8062. +++ linux-4.1.6/include/acpi/platform/aclinux.h 2015-09-08 23:49:06.322065194 +0200
  8063. @@ -123,6 +123,7 @@
  8064. #define acpi_cache_t struct kmem_cache
  8065. #define acpi_spinlock spinlock_t *
  8066. +#define acpi_raw_spinlock raw_spinlock_t *
  8067. #define acpi_cpu_flags unsigned long
  8068. /* Use native linux version of acpi_os_allocate_zeroed */
  8069. @@ -141,6 +142,20 @@
  8070. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_get_thread_id
  8071. #define ACPI_USE_ALTERNATE_PROTOTYPE_acpi_os_create_lock
  8072. +#define acpi_os_create_raw_lock(__handle) \
  8073. +({ \
  8074. + raw_spinlock_t *lock = ACPI_ALLOCATE(sizeof(*lock)); \
  8075. + \
  8076. + if (lock) { \
  8077. + *(__handle) = lock; \
  8078. + raw_spin_lock_init(*(__handle)); \
  8079. + } \
  8080. + lock ? AE_OK : AE_NO_MEMORY; \
  8081. + })
  8082. +
  8083. +#define acpi_os_delete_raw_lock(__handle) kfree(__handle)
  8084. +
  8085. +
  8086. /*
  8087. * OSL interfaces used by debugger/disassembler
  8088. */
  8089. diff -Nur linux-4.1.6.orig/include/asm-generic/bug.h linux-4.1.6/include/asm-generic/bug.h
  8090. --- linux-4.1.6.orig/include/asm-generic/bug.h 2015-08-17 05:52:51.000000000 +0200
  8091. +++ linux-4.1.6/include/asm-generic/bug.h 2015-09-08 23:49:06.322065194 +0200
  8092. @@ -206,6 +206,20 @@
  8093. # define WARN_ON_SMP(x) ({0;})
  8094. #endif
  8095. +#ifdef CONFIG_PREEMPT_RT_BASE
  8096. +# define BUG_ON_RT(c) BUG_ON(c)
  8097. +# define BUG_ON_NONRT(c) do { } while (0)
  8098. +# define WARN_ON_RT(condition) WARN_ON(condition)
  8099. +# define WARN_ON_NONRT(condition) do { } while (0)
  8100. +# define WARN_ON_ONCE_NONRT(condition) do { } while (0)
  8101. +#else
  8102. +# define BUG_ON_RT(c) do { } while (0)
  8103. +# define BUG_ON_NONRT(c) BUG_ON(c)
  8104. +# define WARN_ON_RT(condition) do { } while (0)
  8105. +# define WARN_ON_NONRT(condition) WARN_ON(condition)
  8106. +# define WARN_ON_ONCE_NONRT(condition) WARN_ON_ONCE(condition)
  8107. +#endif
  8108. +
  8109. #endif /* __ASSEMBLY__ */
  8110. #endif
  8111. diff -Nur linux-4.1.6.orig/include/asm-generic/futex.h linux-4.1.6/include/asm-generic/futex.h
  8112. --- linux-4.1.6.orig/include/asm-generic/futex.h 2015-08-17 05:52:51.000000000 +0200
  8113. +++ linux-4.1.6/include/asm-generic/futex.h 2015-09-08 23:49:06.322065194 +0200
  8114. @@ -8,8 +8,7 @@
  8115. #ifndef CONFIG_SMP
  8116. /*
  8117. * The following implementation only for uniprocessor machines.
  8118. - * For UP, it's relies on the fact that pagefault_disable() also disables
  8119. - * preemption to ensure mutual exclusion.
  8120. + * It relies on preempt_disable() ensuring mutual exclusion.
  8121. *
  8122. */
  8123. @@ -38,6 +37,7 @@
  8124. if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
  8125. oparg = 1 << oparg;
  8126. + preempt_disable();
  8127. pagefault_disable();
  8128. ret = -EFAULT;
  8129. @@ -72,6 +72,7 @@
  8130. out_pagefault_enable:
  8131. pagefault_enable();
  8132. + preempt_enable();
  8133. if (ret == 0) {
  8134. switch (cmp) {
  8135. @@ -106,6 +107,7 @@
  8136. {
  8137. u32 val;
  8138. + preempt_disable();
  8139. if (unlikely(get_user(val, uaddr) != 0))
  8140. return -EFAULT;
  8141. @@ -113,6 +115,7 @@
  8142. return -EFAULT;
  8143. *uval = val;
  8144. + preempt_enable();
  8145. return 0;
  8146. }
  8147. diff -Nur linux-4.1.6.orig/include/linux/blkdev.h linux-4.1.6/include/linux/blkdev.h
  8148. --- linux-4.1.6.orig/include/linux/blkdev.h 2015-08-17 05:52:51.000000000 +0200
  8149. +++ linux-4.1.6/include/linux/blkdev.h 2015-09-08 23:49:06.530042129 +0200
  8150. @@ -101,6 +101,7 @@
  8151. struct list_head queuelist;
  8152. union {
  8153. struct call_single_data csd;
  8154. + struct work_struct work;
  8155. unsigned long fifo_time;
  8156. };
  8157. @@ -482,7 +483,7 @@
  8158. struct throtl_data *td;
  8159. #endif
  8160. struct rcu_head rcu_head;
  8161. - wait_queue_head_t mq_freeze_wq;
  8162. + struct swait_head mq_freeze_wq;
  8163. struct percpu_ref mq_usage_counter;
  8164. struct list_head all_q_node;
  8165. diff -Nur linux-4.1.6.orig/include/linux/blk-mq.h linux-4.1.6/include/linux/blk-mq.h
  8166. --- linux-4.1.6.orig/include/linux/blk-mq.h 2015-08-17 05:52:51.000000000 +0200
  8167. +++ linux-4.1.6/include/linux/blk-mq.h 2015-09-08 23:49:06.322065194 +0200
  8168. @@ -202,6 +202,7 @@
  8169. struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
  8170. struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
  8171. +void __blk_mq_complete_request_remote_work(struct work_struct *work);
  8172. int blk_mq_request_started(struct request *rq);
  8173. void blk_mq_start_request(struct request *rq);
  8174. diff -Nur linux-4.1.6.orig/include/linux/bottom_half.h linux-4.1.6/include/linux/bottom_half.h
  8175. --- linux-4.1.6.orig/include/linux/bottom_half.h 2015-08-17 05:52:51.000000000 +0200
  8176. +++ linux-4.1.6/include/linux/bottom_half.h 2015-09-08 23:49:06.530042129 +0200
  8177. @@ -4,6 +4,17 @@
  8178. #include <linux/preempt.h>
  8179. #include <linux/preempt_mask.h>
  8180. +#ifdef CONFIG_PREEMPT_RT_FULL
  8181. +
  8182. +extern void local_bh_disable(void);
  8183. +extern void _local_bh_enable(void);
  8184. +extern void local_bh_enable(void);
  8185. +extern void local_bh_enable_ip(unsigned long ip);
  8186. +extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
  8187. +extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt);
  8188. +
  8189. +#else
  8190. +
  8191. #ifdef CONFIG_TRACE_IRQFLAGS
  8192. extern void __local_bh_disable_ip(unsigned long ip, unsigned int cnt);
  8193. #else
  8194. @@ -31,5 +42,6 @@
  8195. {
  8196. __local_bh_enable_ip(_THIS_IP_, SOFTIRQ_DISABLE_OFFSET);
  8197. }
  8198. +#endif
  8199. #endif /* _LINUX_BH_H */
  8200. diff -Nur linux-4.1.6.orig/include/linux/buffer_head.h linux-4.1.6/include/linux/buffer_head.h
  8201. --- linux-4.1.6.orig/include/linux/buffer_head.h 2015-08-17 05:52:51.000000000 +0200
  8202. +++ linux-4.1.6/include/linux/buffer_head.h 2015-09-08 23:49:06.530042129 +0200
  8203. @@ -75,8 +75,52 @@
  8204. struct address_space *b_assoc_map; /* mapping this buffer is
  8205. associated with */
  8206. atomic_t b_count; /* users using this buffer_head */
  8207. +#ifdef CONFIG_PREEMPT_RT_BASE
  8208. + spinlock_t b_uptodate_lock;
  8209. +#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || \
  8210. + defined(CONFIG_JBD2) || defined(CONFIG_JBD2_MODULE)
  8211. + spinlock_t b_state_lock;
  8212. + spinlock_t b_journal_head_lock;
  8213. +#endif
  8214. +#endif
  8215. };
  8216. +static inline unsigned long bh_uptodate_lock_irqsave(struct buffer_head *bh)
  8217. +{
  8218. + unsigned long flags;
  8219. +
  8220. +#ifndef CONFIG_PREEMPT_RT_BASE
  8221. + local_irq_save(flags);
  8222. + bit_spin_lock(BH_Uptodate_Lock, &bh->b_state);
  8223. +#else
  8224. + spin_lock_irqsave(&bh->b_uptodate_lock, flags);
  8225. +#endif
  8226. + return flags;
  8227. +}
  8228. +
  8229. +static inline void
  8230. +bh_uptodate_unlock_irqrestore(struct buffer_head *bh, unsigned long flags)
  8231. +{
  8232. +#ifndef CONFIG_PREEMPT_RT_BASE
  8233. + bit_spin_unlock(BH_Uptodate_Lock, &bh->b_state);
  8234. + local_irq_restore(flags);
  8235. +#else
  8236. + spin_unlock_irqrestore(&bh->b_uptodate_lock, flags);
  8237. +#endif
  8238. +}
  8239. +
  8240. +static inline void buffer_head_init_locks(struct buffer_head *bh)
  8241. +{
  8242. +#ifdef CONFIG_PREEMPT_RT_BASE
  8243. + spin_lock_init(&bh->b_uptodate_lock);
  8244. +#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || \
  8245. + defined(CONFIG_JBD2) || defined(CONFIG_JBD2_MODULE)
  8246. + spin_lock_init(&bh->b_state_lock);
  8247. + spin_lock_init(&bh->b_journal_head_lock);
  8248. +#endif
  8249. +#endif
  8250. +}
  8251. +
  8252. /*
  8253. * macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
  8254. * and buffer_foo() functions.
  8255. diff -Nur linux-4.1.6.orig/include/linux/cgroup.h linux-4.1.6/include/linux/cgroup.h
  8256. --- linux-4.1.6.orig/include/linux/cgroup.h 2015-08-17 05:52:51.000000000 +0200
  8257. +++ linux-4.1.6/include/linux/cgroup.h 2015-09-08 23:49:06.534041686 +0200
  8258. @@ -22,6 +22,7 @@
  8259. #include <linux/seq_file.h>
  8260. #include <linux/kernfs.h>
  8261. #include <linux/wait.h>
  8262. +#include <linux/work-simple.h>
  8263. #ifdef CONFIG_CGROUPS
  8264. @@ -91,6 +92,7 @@
  8265. /* percpu_ref killing and RCU release */
  8266. struct rcu_head rcu_head;
  8267. struct work_struct destroy_work;
  8268. + struct swork_event destroy_swork;
  8269. };
  8270. /* bits in struct cgroup_subsys_state flags field */
  8271. diff -Nur linux-4.1.6.orig/include/linux/completion.h linux-4.1.6/include/linux/completion.h
  8272. --- linux-4.1.6.orig/include/linux/completion.h 2015-08-17 05:52:51.000000000 +0200
  8273. +++ linux-4.1.6/include/linux/completion.h 2015-09-08 23:49:06.534041686 +0200
  8274. @@ -7,8 +7,7 @@
  8275. * Atomic wait-for-completion handler data structures.
  8276. * See kernel/sched/completion.c for details.
  8277. */
  8278. -
  8279. -#include <linux/wait.h>
  8280. +#include <linux/wait-simple.h>
  8281. /*
  8282. * struct completion - structure used to maintain state for a "completion"
  8283. @@ -24,11 +23,11 @@
  8284. */
  8285. struct completion {
  8286. unsigned int done;
  8287. - wait_queue_head_t wait;
  8288. + struct swait_head wait;
  8289. };
  8290. #define COMPLETION_INITIALIZER(work) \
  8291. - { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) }
  8292. + { 0, SWAIT_HEAD_INITIALIZER((work).wait) }
  8293. #define COMPLETION_INITIALIZER_ONSTACK(work) \
  8294. ({ init_completion(&work); work; })
  8295. @@ -73,7 +72,7 @@
  8296. static inline void init_completion(struct completion *x)
  8297. {
  8298. x->done = 0;
  8299. - init_waitqueue_head(&x->wait);
  8300. + init_swait_head(&x->wait);
  8301. }
  8302. /**
  8303. diff -Nur linux-4.1.6.orig/include/linux/cpu.h linux-4.1.6/include/linux/cpu.h
  8304. --- linux-4.1.6.orig/include/linux/cpu.h 2015-08-17 05:52:51.000000000 +0200
  8305. +++ linux-4.1.6/include/linux/cpu.h 2015-09-08 23:49:06.534041686 +0200
  8306. @@ -231,6 +231,8 @@
  8307. extern void put_online_cpus(void);
  8308. extern void cpu_hotplug_disable(void);
  8309. extern void cpu_hotplug_enable(void);
  8310. +extern void pin_current_cpu(void);
  8311. +extern void unpin_current_cpu(void);
  8312. #define hotcpu_notifier(fn, pri) cpu_notifier(fn, pri)
  8313. #define __hotcpu_notifier(fn, pri) __cpu_notifier(fn, pri)
  8314. #define register_hotcpu_notifier(nb) register_cpu_notifier(nb)
  8315. @@ -249,6 +251,8 @@
  8316. #define put_online_cpus() do { } while (0)
  8317. #define cpu_hotplug_disable() do { } while (0)
  8318. #define cpu_hotplug_enable() do { } while (0)
  8319. +static inline void pin_current_cpu(void) { }
  8320. +static inline void unpin_current_cpu(void) { }
  8321. #define hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  8322. #define __hotcpu_notifier(fn, pri) do { (void)(fn); } while (0)
  8323. /* These aren't inline functions due to a GCC bug. */
  8324. diff -Nur linux-4.1.6.orig/include/linux/delay.h linux-4.1.6/include/linux/delay.h
  8325. --- linux-4.1.6.orig/include/linux/delay.h 2015-08-17 05:52:51.000000000 +0200
  8326. +++ linux-4.1.6/include/linux/delay.h 2015-09-08 23:49:06.534041686 +0200
  8327. @@ -52,4 +52,10 @@
  8328. msleep(seconds * 1000);
  8329. }
  8330. +#ifdef CONFIG_PREEMPT_RT_FULL
  8331. +extern void cpu_chill(void);
  8332. +#else
  8333. +# define cpu_chill() cpu_relax()
  8334. +#endif
  8335. +
  8336. #endif /* defined(_LINUX_DELAY_H) */
  8337. diff -Nur linux-4.1.6.orig/include/linux/ftrace_event.h linux-4.1.6/include/linux/ftrace_event.h
  8338. --- linux-4.1.6.orig/include/linux/ftrace_event.h 2015-08-17 05:52:51.000000000 +0200
  8339. +++ linux-4.1.6/include/linux/ftrace_event.h 2015-09-08 23:49:06.534041686 +0200
  8340. @@ -66,6 +66,9 @@
  8341. unsigned char flags;
  8342. unsigned char preempt_count;
  8343. int pid;
  8344. + unsigned short migrate_disable;
  8345. + unsigned short padding;
  8346. + unsigned char preempt_lazy_count;
  8347. };
  8348. #define FTRACE_MAX_EVENT \
  8349. diff -Nur linux-4.1.6.orig/include/linux/highmem.h linux-4.1.6/include/linux/highmem.h
  8350. --- linux-4.1.6.orig/include/linux/highmem.h 2015-08-17 05:52:51.000000000 +0200
  8351. +++ linux-4.1.6/include/linux/highmem.h 2015-09-08 23:49:06.534041686 +0200
  8352. @@ -7,6 +7,7 @@
  8353. #include <linux/mm.h>
  8354. #include <linux/uaccess.h>
  8355. #include <linux/hardirq.h>
  8356. +#include <linux/sched.h>
  8357. #include <asm/cacheflush.h>
  8358. @@ -65,6 +66,7 @@
  8359. static inline void *kmap_atomic(struct page *page)
  8360. {
  8361. + preempt_disable();
  8362. pagefault_disable();
  8363. return page_address(page);
  8364. }
  8365. @@ -73,6 +75,7 @@
  8366. static inline void __kunmap_atomic(void *addr)
  8367. {
  8368. pagefault_enable();
  8369. + preempt_enable();
  8370. }
  8371. #define kmap_atomic_pfn(pfn) kmap_atomic(pfn_to_page(pfn))
  8372. @@ -85,32 +88,51 @@
  8373. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  8374. +#ifndef CONFIG_PREEMPT_RT_FULL
  8375. DECLARE_PER_CPU(int, __kmap_atomic_idx);
  8376. +#endif
  8377. static inline int kmap_atomic_idx_push(void)
  8378. {
  8379. +#ifndef CONFIG_PREEMPT_RT_FULL
  8380. int idx = __this_cpu_inc_return(__kmap_atomic_idx) - 1;
  8381. -#ifdef CONFIG_DEBUG_HIGHMEM
  8382. +# ifdef CONFIG_DEBUG_HIGHMEM
  8383. WARN_ON_ONCE(in_irq() && !irqs_disabled());
  8384. BUG_ON(idx >= KM_TYPE_NR);
  8385. -#endif
  8386. +# endif
  8387. return idx;
  8388. +#else
  8389. + current->kmap_idx++;
  8390. + BUG_ON(current->kmap_idx > KM_TYPE_NR);
  8391. + return current->kmap_idx - 1;
  8392. +#endif
  8393. }
  8394. static inline int kmap_atomic_idx(void)
  8395. {
  8396. +#ifndef CONFIG_PREEMPT_RT_FULL
  8397. return __this_cpu_read(__kmap_atomic_idx) - 1;
  8398. +#else
  8399. + return current->kmap_idx - 1;
  8400. +#endif
  8401. }
  8402. static inline void kmap_atomic_idx_pop(void)
  8403. {
  8404. -#ifdef CONFIG_DEBUG_HIGHMEM
  8405. +#ifndef CONFIG_PREEMPT_RT_FULL
  8406. +# ifdef CONFIG_DEBUG_HIGHMEM
  8407. int idx = __this_cpu_dec_return(__kmap_atomic_idx);
  8408. BUG_ON(idx < 0);
  8409. -#else
  8410. +# else
  8411. __this_cpu_dec(__kmap_atomic_idx);
  8412. +# endif
  8413. +#else
  8414. + current->kmap_idx--;
  8415. +# ifdef CONFIG_DEBUG_HIGHMEM
  8416. + BUG_ON(current->kmap_idx < 0);
  8417. +# endif
  8418. #endif
  8419. }
  8420. diff -Nur linux-4.1.6.orig/include/linux/hrtimer.h linux-4.1.6/include/linux/hrtimer.h
  8421. --- linux-4.1.6.orig/include/linux/hrtimer.h 2015-08-17 05:52:51.000000000 +0200
  8422. +++ linux-4.1.6/include/linux/hrtimer.h 2015-09-08 23:49:06.534041686 +0200
  8423. @@ -111,6 +111,11 @@
  8424. enum hrtimer_restart (*function)(struct hrtimer *);
  8425. struct hrtimer_clock_base *base;
  8426. unsigned long state;
  8427. + struct list_head cb_entry;
  8428. + int irqsafe;
  8429. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  8430. + ktime_t praecox;
  8431. +#endif
  8432. #ifdef CONFIG_TIMER_STATS
  8433. int start_pid;
  8434. void *start_site;
  8435. @@ -147,6 +152,7 @@
  8436. int index;
  8437. clockid_t clockid;
  8438. struct timerqueue_head active;
  8439. + struct list_head expired;
  8440. ktime_t resolution;
  8441. ktime_t (*get_time)(void);
  8442. ktime_t softirq_time;
  8443. @@ -194,6 +200,9 @@
  8444. unsigned long nr_hangs;
  8445. ktime_t max_hang_time;
  8446. #endif
  8447. +#ifdef CONFIG_PREEMPT_RT_BASE
  8448. + wait_queue_head_t wait;
  8449. +#endif
  8450. struct hrtimer_clock_base clock_base[HRTIMER_MAX_CLOCK_BASES];
  8451. };
  8452. @@ -381,6 +390,13 @@
  8453. return hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
  8454. }
  8455. +/* Softirq preemption could deadlock timer removal */
  8456. +#ifdef CONFIG_PREEMPT_RT_BASE
  8457. + extern void hrtimer_wait_for_timer(const struct hrtimer *timer);
  8458. +#else
  8459. +# define hrtimer_wait_for_timer(timer) do { cpu_relax(); } while (0)
  8460. +#endif
  8461. +
  8462. /* Query timers: */
  8463. extern ktime_t hrtimer_get_remaining(const struct hrtimer *timer);
  8464. extern int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp);
  8465. diff -Nur linux-4.1.6.orig/include/linux/idr.h linux-4.1.6/include/linux/idr.h
  8466. --- linux-4.1.6.orig/include/linux/idr.h 2015-08-17 05:52:51.000000000 +0200
  8467. +++ linux-4.1.6/include/linux/idr.h 2015-09-08 23:49:06.534041686 +0200
  8468. @@ -95,10 +95,14 @@
  8469. * Each idr_preload() should be matched with an invocation of this
  8470. * function. See idr_preload() for details.
  8471. */
  8472. +#ifdef CONFIG_PREEMPT_RT_FULL
  8473. +void idr_preload_end(void);
  8474. +#else
  8475. static inline void idr_preload_end(void)
  8476. {
  8477. preempt_enable();
  8478. }
  8479. +#endif
  8480. /**
  8481. * idr_find - return pointer for given id
  8482. diff -Nur linux-4.1.6.orig/include/linux/init_task.h linux-4.1.6/include/linux/init_task.h
  8483. --- linux-4.1.6.orig/include/linux/init_task.h 2015-08-17 05:52:51.000000000 +0200
  8484. +++ linux-4.1.6/include/linux/init_task.h 2015-09-08 23:49:06.542040801 +0200
  8485. @@ -147,9 +147,16 @@
  8486. # define INIT_PERF_EVENTS(tsk)
  8487. #endif
  8488. +#ifdef CONFIG_PREEMPT_RT_BASE
  8489. +# define INIT_TIMER_LIST .posix_timer_list = NULL,
  8490. +#else
  8491. +# define INIT_TIMER_LIST
  8492. +#endif
  8493. +
  8494. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  8495. # define INIT_VTIME(tsk) \
  8496. - .vtime_seqlock = __SEQLOCK_UNLOCKED(tsk.vtime_seqlock), \
  8497. + .vtime_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.vtime_lock), \
  8498. + .vtime_seq = SEQCNT_ZERO(tsk.vtime_seq), \
  8499. .vtime_snap = 0, \
  8500. .vtime_snap_whence = VTIME_SYS,
  8501. #else
  8502. @@ -238,6 +245,7 @@
  8503. .cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
  8504. .pi_lock = __RAW_SPIN_LOCK_UNLOCKED(tsk.pi_lock), \
  8505. .timer_slack_ns = 50000, /* 50 usec default slack */ \
  8506. + INIT_TIMER_LIST \
  8507. .pids = { \
  8508. [PIDTYPE_PID] = INIT_PID_LINK(PIDTYPE_PID), \
  8509. [PIDTYPE_PGID] = INIT_PID_LINK(PIDTYPE_PGID), \
  8510. diff -Nur linux-4.1.6.orig/include/linux/interrupt.h linux-4.1.6/include/linux/interrupt.h
  8511. --- linux-4.1.6.orig/include/linux/interrupt.h 2015-08-17 05:52:51.000000000 +0200
  8512. +++ linux-4.1.6/include/linux/interrupt.h 2015-09-08 23:49:06.542040801 +0200
  8513. @@ -61,6 +61,7 @@
  8514. * interrupt handler after suspending interrupts. For system
  8515. * wakeup devices users need to implement wakeup detection in
  8516. * their interrupt handlers.
  8517. + * IRQF_NO_SOFTIRQ_CALL - Do not process softirqs in the irq thread context (RT)
  8518. */
  8519. #define IRQF_SHARED 0x00000080
  8520. #define IRQF_PROBE_SHARED 0x00000100
  8521. @@ -74,6 +75,7 @@
  8522. #define IRQF_NO_THREAD 0x00010000
  8523. #define IRQF_EARLY_RESUME 0x00020000
  8524. #define IRQF_COND_SUSPEND 0x00040000
  8525. +#define IRQF_NO_SOFTIRQ_CALL 0x00080000
  8526. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  8527. @@ -184,7 +186,7 @@
  8528. #ifdef CONFIG_LOCKDEP
  8529. # define local_irq_enable_in_hardirq() do { } while (0)
  8530. #else
  8531. -# define local_irq_enable_in_hardirq() local_irq_enable()
  8532. +# define local_irq_enable_in_hardirq() local_irq_enable_nort()
  8533. #endif
  8534. extern void disable_irq_nosync(unsigned int irq);
  8535. @@ -215,6 +217,7 @@
  8536. unsigned int irq;
  8537. struct kref kref;
  8538. struct work_struct work;
  8539. + struct list_head list;
  8540. void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  8541. void (*release)(struct kref *ref);
  8542. };
  8543. @@ -377,9 +380,13 @@
  8544. bool state);
  8545. #ifdef CONFIG_IRQ_FORCED_THREADING
  8546. +# ifndef CONFIG_PREEMPT_RT_BASE
  8547. extern bool force_irqthreads;
  8548. +# else
  8549. +# define force_irqthreads (true)
  8550. +# endif
  8551. #else
  8552. -#define force_irqthreads (0)
  8553. +#define force_irqthreads (false)
  8554. #endif
  8555. #ifndef __ARCH_SET_SOFTIRQ_PENDING
  8556. @@ -435,9 +442,10 @@
  8557. void (*action)(struct softirq_action *);
  8558. };
  8559. +#ifndef CONFIG_PREEMPT_RT_FULL
  8560. asmlinkage void do_softirq(void);
  8561. asmlinkage void __do_softirq(void);
  8562. -
  8563. +static inline void thread_do_softirq(void) { do_softirq(); }
  8564. #ifdef __ARCH_HAS_DO_SOFTIRQ
  8565. void do_softirq_own_stack(void);
  8566. #else
  8567. @@ -446,6 +454,9 @@
  8568. __do_softirq();
  8569. }
  8570. #endif
  8571. +#else
  8572. +extern void thread_do_softirq(void);
  8573. +#endif
  8574. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  8575. extern void softirq_init(void);
  8576. @@ -453,6 +464,7 @@
  8577. extern void raise_softirq_irqoff(unsigned int nr);
  8578. extern void raise_softirq(unsigned int nr);
  8579. +extern void softirq_check_pending_idle(void);
  8580. DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  8581. @@ -474,8 +486,9 @@
  8582. to be executed on some cpu at least once after this.
  8583. * If the tasklet is already scheduled, but its execution is still not
  8584. started, it will be executed only once.
  8585. - * If this tasklet is already running on another CPU (or schedule is called
  8586. - from tasklet itself), it is rescheduled for later.
  8587. + * If this tasklet is already running on another CPU, it is rescheduled
  8588. + for later.
  8589. + * Schedule must not be called from the tasklet itself (a lockup occurs)
  8590. * Tasklet is strictly serialized wrt itself, but not
  8591. wrt another tasklets. If client needs some intertask synchronization,
  8592. he makes it with spinlocks.
  8593. @@ -500,27 +513,36 @@
  8594. enum
  8595. {
  8596. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  8597. - TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  8598. + TASKLET_STATE_RUN, /* Tasklet is running (SMP only) */
  8599. + TASKLET_STATE_PENDING /* Tasklet is pending */
  8600. };
  8601. -#ifdef CONFIG_SMP
  8602. +#define TASKLET_STATEF_SCHED (1 << TASKLET_STATE_SCHED)
  8603. +#define TASKLET_STATEF_RUN (1 << TASKLET_STATE_RUN)
  8604. +#define TASKLET_STATEF_PENDING (1 << TASKLET_STATE_PENDING)
  8605. +
  8606. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  8607. static inline int tasklet_trylock(struct tasklet_struct *t)
  8608. {
  8609. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  8610. }
  8611. +static inline int tasklet_tryunlock(struct tasklet_struct *t)
  8612. +{
  8613. + return cmpxchg(&t->state, TASKLET_STATEF_RUN, 0) == TASKLET_STATEF_RUN;
  8614. +}
  8615. +
  8616. static inline void tasklet_unlock(struct tasklet_struct *t)
  8617. {
  8618. smp_mb__before_atomic();
  8619. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  8620. }
  8621. -static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  8622. -{
  8623. - while (test_bit(TASKLET_STATE_RUN, &(t)->state)) { barrier(); }
  8624. -}
  8625. +extern void tasklet_unlock_wait(struct tasklet_struct *t);
  8626. +
  8627. #else
  8628. #define tasklet_trylock(t) 1
  8629. +#define tasklet_tryunlock(t) 1
  8630. #define tasklet_unlock_wait(t) do { } while (0)
  8631. #define tasklet_unlock(t) do { } while (0)
  8632. #endif
  8633. @@ -569,12 +591,7 @@
  8634. smp_mb();
  8635. }
  8636. -static inline void tasklet_enable(struct tasklet_struct *t)
  8637. -{
  8638. - smp_mb__before_atomic();
  8639. - atomic_dec(&t->count);
  8640. -}
  8641. -
  8642. +extern void tasklet_enable(struct tasklet_struct *t);
  8643. extern void tasklet_kill(struct tasklet_struct *t);
  8644. extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  8645. extern void tasklet_init(struct tasklet_struct *t,
  8646. @@ -605,6 +622,12 @@
  8647. tasklet_kill(&ttimer->tasklet);
  8648. }
  8649. +#ifdef CONFIG_PREEMPT_RT_FULL
  8650. +extern void softirq_early_init(void);
  8651. +#else
  8652. +static inline void softirq_early_init(void) { }
  8653. +#endif
  8654. +
  8655. /*
  8656. * Autoprobing for irqs:
  8657. *
  8658. diff -Nur linux-4.1.6.orig/include/linux/io-mapping.h linux-4.1.6/include/linux/io-mapping.h
  8659. --- linux-4.1.6.orig/include/linux/io-mapping.h 2015-08-17 05:52:51.000000000 +0200
  8660. +++ linux-4.1.6/include/linux/io-mapping.h 2015-09-08 23:49:06.542040801 +0200
  8661. @@ -141,6 +141,7 @@
  8662. io_mapping_map_atomic_wc(struct io_mapping *mapping,
  8663. unsigned long offset)
  8664. {
  8665. + preempt_disable();
  8666. pagefault_disable();
  8667. return ((char __force __iomem *) mapping) + offset;
  8668. }
  8669. @@ -149,6 +150,7 @@
  8670. io_mapping_unmap_atomic(void __iomem *vaddr)
  8671. {
  8672. pagefault_enable();
  8673. + preempt_enable();
  8674. }
  8675. /* Non-atomic map/unmap */
  8676. diff -Nur linux-4.1.6.orig/include/linux/irqdesc.h linux-4.1.6/include/linux/irqdesc.h
  8677. --- linux-4.1.6.orig/include/linux/irqdesc.h 2015-08-17 05:52:51.000000000 +0200
  8678. +++ linux-4.1.6/include/linux/irqdesc.h 2015-09-08 23:49:06.546040357 +0200
  8679. @@ -63,6 +63,7 @@
  8680. unsigned int irqs_unhandled;
  8681. atomic_t threads_handled;
  8682. int threads_handled_last;
  8683. + u64 random_ip;
  8684. raw_spinlock_t lock;
  8685. struct cpumask *percpu_enabled;
  8686. #ifdef CONFIG_SMP
  8687. diff -Nur linux-4.1.6.orig/include/linux/irqflags.h linux-4.1.6/include/linux/irqflags.h
  8688. --- linux-4.1.6.orig/include/linux/irqflags.h 2015-08-17 05:52:51.000000000 +0200
  8689. +++ linux-4.1.6/include/linux/irqflags.h 2015-09-08 23:49:06.546040357 +0200
  8690. @@ -25,8 +25,6 @@
  8691. # define trace_softirqs_enabled(p) ((p)->softirqs_enabled)
  8692. # define trace_hardirq_enter() do { current->hardirq_context++; } while (0)
  8693. # define trace_hardirq_exit() do { current->hardirq_context--; } while (0)
  8694. -# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  8695. -# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  8696. # define INIT_TRACE_IRQFLAGS .softirqs_enabled = 1,
  8697. #else
  8698. # define trace_hardirqs_on() do { } while (0)
  8699. @@ -39,9 +37,15 @@
  8700. # define trace_softirqs_enabled(p) 0
  8701. # define trace_hardirq_enter() do { } while (0)
  8702. # define trace_hardirq_exit() do { } while (0)
  8703. +# define INIT_TRACE_IRQFLAGS
  8704. +#endif
  8705. +
  8706. +#if defined(CONFIG_TRACE_IRQFLAGS) && !defined(CONFIG_PREEMPT_RT_FULL)
  8707. +# define lockdep_softirq_enter() do { current->softirq_context++; } while (0)
  8708. +# define lockdep_softirq_exit() do { current->softirq_context--; } while (0)
  8709. +#else
  8710. # define lockdep_softirq_enter() do { } while (0)
  8711. # define lockdep_softirq_exit() do { } while (0)
  8712. -# define INIT_TRACE_IRQFLAGS
  8713. #endif
  8714. #if defined(CONFIG_IRQSOFF_TRACER) || \
  8715. @@ -148,4 +152,23 @@
  8716. #define irqs_disabled_flags(flags) raw_irqs_disabled_flags(flags)
  8717. +/*
  8718. + * local_irq* variants depending on RT/!RT
  8719. + */
  8720. +#ifdef CONFIG_PREEMPT_RT_FULL
  8721. +# define local_irq_disable_nort() do { } while (0)
  8722. +# define local_irq_enable_nort() do { } while (0)
  8723. +# define local_irq_save_nort(flags) local_save_flags(flags)
  8724. +# define local_irq_restore_nort(flags) (void)(flags)
  8725. +# define local_irq_disable_rt() local_irq_disable()
  8726. +# define local_irq_enable_rt() local_irq_enable()
  8727. +#else
  8728. +# define local_irq_disable_nort() local_irq_disable()
  8729. +# define local_irq_enable_nort() local_irq_enable()
  8730. +# define local_irq_save_nort(flags) local_irq_save(flags)
  8731. +# define local_irq_restore_nort(flags) local_irq_restore(flags)
  8732. +# define local_irq_disable_rt() do { } while (0)
  8733. +# define local_irq_enable_rt() do { } while (0)
  8734. +#endif
  8735. +
  8736. #endif
  8737. diff -Nur linux-4.1.6.orig/include/linux/irq.h linux-4.1.6/include/linux/irq.h
  8738. --- linux-4.1.6.orig/include/linux/irq.h 2015-08-17 05:52:51.000000000 +0200
  8739. +++ linux-4.1.6/include/linux/irq.h 2015-09-08 23:49:06.542040801 +0200
  8740. @@ -72,6 +72,7 @@
  8741. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  8742. * it from the spurious interrupt detection
  8743. * mechanism and from core side polling.
  8744. + * IRQ_NO_SOFTIRQ_CALL - No softirq processing in the irq thread context (RT)
  8745. */
  8746. enum {
  8747. IRQ_TYPE_NONE = 0x00000000,
  8748. @@ -97,13 +98,14 @@
  8749. IRQ_NOTHREAD = (1 << 16),
  8750. IRQ_PER_CPU_DEVID = (1 << 17),
  8751. IRQ_IS_POLLED = (1 << 18),
  8752. + IRQ_NO_SOFTIRQ_CALL = (1 << 19),
  8753. };
  8754. #define IRQF_MODIFY_MASK \
  8755. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  8756. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  8757. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  8758. - IRQ_IS_POLLED)
  8759. + IRQ_IS_POLLED | IRQ_NO_SOFTIRQ_CALL)
  8760. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  8761. diff -Nur linux-4.1.6.orig/include/linux/irq_work.h linux-4.1.6/include/linux/irq_work.h
  8762. --- linux-4.1.6.orig/include/linux/irq_work.h 2015-08-17 05:52:51.000000000 +0200
  8763. +++ linux-4.1.6/include/linux/irq_work.h 2015-09-08 23:49:06.542040801 +0200
  8764. @@ -16,6 +16,7 @@
  8765. #define IRQ_WORK_BUSY 2UL
  8766. #define IRQ_WORK_FLAGS 3UL
  8767. #define IRQ_WORK_LAZY 4UL /* Doesn't want IPI, wait for tick */
  8768. +#define IRQ_WORK_HARD_IRQ 8UL /* Run hard IRQ context, even on RT */
  8769. struct irq_work {
  8770. unsigned long flags;
  8771. diff -Nur linux-4.1.6.orig/include/linux/jbd_common.h linux-4.1.6/include/linux/jbd_common.h
  8772. --- linux-4.1.6.orig/include/linux/jbd_common.h 2015-08-17 05:52:51.000000000 +0200
  8773. +++ linux-4.1.6/include/linux/jbd_common.h 2015-09-08 23:49:06.546040357 +0200
  8774. @@ -15,32 +15,56 @@
  8775. static inline void jbd_lock_bh_state(struct buffer_head *bh)
  8776. {
  8777. +#ifndef CONFIG_PREEMPT_RT_BASE
  8778. bit_spin_lock(BH_State, &bh->b_state);
  8779. +#else
  8780. + spin_lock(&bh->b_state_lock);
  8781. +#endif
  8782. }
  8783. static inline int jbd_trylock_bh_state(struct buffer_head *bh)
  8784. {
  8785. +#ifndef CONFIG_PREEMPT_RT_BASE
  8786. return bit_spin_trylock(BH_State, &bh->b_state);
  8787. +#else
  8788. + return spin_trylock(&bh->b_state_lock);
  8789. +#endif
  8790. }
  8791. static inline int jbd_is_locked_bh_state(struct buffer_head *bh)
  8792. {
  8793. +#ifndef CONFIG_PREEMPT_RT_BASE
  8794. return bit_spin_is_locked(BH_State, &bh->b_state);
  8795. +#else
  8796. + return spin_is_locked(&bh->b_state_lock);
  8797. +#endif
  8798. }
  8799. static inline void jbd_unlock_bh_state(struct buffer_head *bh)
  8800. {
  8801. +#ifndef CONFIG_PREEMPT_RT_BASE
  8802. bit_spin_unlock(BH_State, &bh->b_state);
  8803. +#else
  8804. + spin_unlock(&bh->b_state_lock);
  8805. +#endif
  8806. }
  8807. static inline void jbd_lock_bh_journal_head(struct buffer_head *bh)
  8808. {
  8809. +#ifndef CONFIG_PREEMPT_RT_BASE
  8810. bit_spin_lock(BH_JournalHead, &bh->b_state);
  8811. +#else
  8812. + spin_lock(&bh->b_journal_head_lock);
  8813. +#endif
  8814. }
  8815. static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh)
  8816. {
  8817. +#ifndef CONFIG_PREEMPT_RT_BASE
  8818. bit_spin_unlock(BH_JournalHead, &bh->b_state);
  8819. +#else
  8820. + spin_unlock(&bh->b_journal_head_lock);
  8821. +#endif
  8822. }
  8823. #endif
  8824. diff -Nur linux-4.1.6.orig/include/linux/kdb.h linux-4.1.6/include/linux/kdb.h
  8825. --- linux-4.1.6.orig/include/linux/kdb.h 2015-08-17 05:52:51.000000000 +0200
  8826. +++ linux-4.1.6/include/linux/kdb.h 2015-09-08 23:49:06.546040357 +0200
  8827. @@ -167,6 +167,7 @@
  8828. extern __printf(1, 2) int kdb_printf(const char *, ...);
  8829. typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
  8830. +#define in_kdb_printk() (kdb_trap_printk)
  8831. extern void kdb_init(int level);
  8832. /* Access to kdb specific polling devices */
  8833. @@ -201,6 +202,7 @@
  8834. extern int kdb_unregister(char *);
  8835. #else /* ! CONFIG_KGDB_KDB */
  8836. static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
  8837. +#define in_kdb_printk() (0)
  8838. static inline void kdb_init(int level) {}
  8839. static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
  8840. char *help, short minlen) { return 0; }
  8841. diff -Nur linux-4.1.6.orig/include/linux/kernel.h linux-4.1.6/include/linux/kernel.h
  8842. --- linux-4.1.6.orig/include/linux/kernel.h 2015-08-17 05:52:51.000000000 +0200
  8843. +++ linux-4.1.6/include/linux/kernel.h 2015-09-08 23:49:06.546040357 +0200
  8844. @@ -188,6 +188,9 @@
  8845. */
  8846. # define might_sleep() \
  8847. do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  8848. +
  8849. +# define might_sleep_no_state_check() \
  8850. + do { ___might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
  8851. # define sched_annotate_sleep() (current->task_state_change = 0)
  8852. #else
  8853. static inline void ___might_sleep(const char *file, int line,
  8854. @@ -195,6 +198,7 @@
  8855. static inline void __might_sleep(const char *file, int line,
  8856. int preempt_offset) { }
  8857. # define might_sleep() do { might_resched(); } while (0)
  8858. +# define might_sleep_no_state_check() do { might_resched(); } while (0)
  8859. # define sched_annotate_sleep() do { } while (0)
  8860. #endif
  8861. @@ -244,7 +248,8 @@
  8862. #if defined(CONFIG_MMU) && \
  8863. (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP))
  8864. -void might_fault(void);
  8865. +#define might_fault() __might_fault(__FILE__, __LINE__)
  8866. +void __might_fault(const char *file, int line);
  8867. #else
  8868. static inline void might_fault(void) { }
  8869. #endif
  8870. @@ -466,6 +471,7 @@
  8871. SYSTEM_HALT,
  8872. SYSTEM_POWER_OFF,
  8873. SYSTEM_RESTART,
  8874. + SYSTEM_SUSPEND,
  8875. } system_state;
  8876. #define TAINT_PROPRIETARY_MODULE 0
  8877. diff -Nur linux-4.1.6.orig/include/linux/kvm_host.h linux-4.1.6/include/linux/kvm_host.h
  8878. --- linux-4.1.6.orig/include/linux/kvm_host.h 2015-08-17 05:52:51.000000000 +0200
  8879. +++ linux-4.1.6/include/linux/kvm_host.h 2015-09-08 23:49:06.546040357 +0200
  8880. @@ -230,7 +230,7 @@
  8881. int fpu_active;
  8882. int guest_fpu_loaded, guest_xcr0_loaded;
  8883. - wait_queue_head_t wq;
  8884. + struct swait_head wq;
  8885. struct pid *pid;
  8886. int sigset_active;
  8887. sigset_t sigset;
  8888. @@ -690,7 +690,7 @@
  8889. }
  8890. #endif
  8891. -static inline wait_queue_head_t *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  8892. +static inline struct swait_head *kvm_arch_vcpu_wq(struct kvm_vcpu *vcpu)
  8893. {
  8894. #ifdef __KVM_HAVE_ARCH_WQP
  8895. return vcpu->arch.wqp;
  8896. diff -Nur linux-4.1.6.orig/include/linux/lglock.h linux-4.1.6/include/linux/lglock.h
  8897. --- linux-4.1.6.orig/include/linux/lglock.h 2015-08-17 05:52:51.000000000 +0200
  8898. +++ linux-4.1.6/include/linux/lglock.h 2015-09-08 23:49:06.546040357 +0200
  8899. @@ -34,22 +34,39 @@
  8900. #endif
  8901. struct lglock {
  8902. +#ifndef CONFIG_PREEMPT_RT_FULL
  8903. arch_spinlock_t __percpu *lock;
  8904. +#else
  8905. + struct rt_mutex __percpu *lock;
  8906. +#endif
  8907. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  8908. struct lock_class_key lock_key;
  8909. struct lockdep_map lock_dep_map;
  8910. #endif
  8911. };
  8912. -#define DEFINE_LGLOCK(name) \
  8913. +#ifndef CONFIG_PREEMPT_RT_FULL
  8914. +# define DEFINE_LGLOCK(name) \
  8915. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  8916. = __ARCH_SPIN_LOCK_UNLOCKED; \
  8917. struct lglock name = { .lock = &name ## _lock }
  8918. -#define DEFINE_STATIC_LGLOCK(name) \
  8919. +# define DEFINE_STATIC_LGLOCK(name) \
  8920. static DEFINE_PER_CPU(arch_spinlock_t, name ## _lock) \
  8921. = __ARCH_SPIN_LOCK_UNLOCKED; \
  8922. static struct lglock name = { .lock = &name ## _lock }
  8923. +#else
  8924. +
  8925. +# define DEFINE_LGLOCK(name) \
  8926. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  8927. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  8928. + struct lglock name = { .lock = &name ## _lock }
  8929. +
  8930. +# define DEFINE_STATIC_LGLOCK(name) \
  8931. + static DEFINE_PER_CPU(struct rt_mutex, name ## _lock) \
  8932. + = __RT_MUTEX_INITIALIZER( name ## _lock); \
  8933. + static struct lglock name = { .lock = &name ## _lock }
  8934. +#endif
  8935. void lg_lock_init(struct lglock *lg, char *name);
  8936. void lg_local_lock(struct lglock *lg);
  8937. @@ -59,6 +76,12 @@
  8938. void lg_global_lock(struct lglock *lg);
  8939. void lg_global_unlock(struct lglock *lg);
  8940. +#ifndef CONFIG_PREEMPT_RT_FULL
  8941. +#define lg_global_trylock_relax(name) lg_global_lock(name)
  8942. +#else
  8943. +void lg_global_trylock_relax(struct lglock *lg);
  8944. +#endif
  8945. +
  8946. #else
  8947. /* When !CONFIG_SMP, map lglock to spinlock */
  8948. #define lglock spinlock
  8949. diff -Nur linux-4.1.6.orig/include/linux/list_bl.h linux-4.1.6/include/linux/list_bl.h
  8950. --- linux-4.1.6.orig/include/linux/list_bl.h 2015-08-17 05:52:51.000000000 +0200
  8951. +++ linux-4.1.6/include/linux/list_bl.h 2015-09-08 23:49:06.546040357 +0200
  8952. @@ -2,6 +2,7 @@
  8953. #define _LINUX_LIST_BL_H
  8954. #include <linux/list.h>
  8955. +#include <linux/spinlock.h>
  8956. #include <linux/bit_spinlock.h>
  8957. /*
  8958. @@ -32,13 +33,22 @@
  8959. struct hlist_bl_head {
  8960. struct hlist_bl_node *first;
  8961. +#ifdef CONFIG_PREEMPT_RT_BASE
  8962. + raw_spinlock_t lock;
  8963. +#endif
  8964. };
  8965. struct hlist_bl_node {
  8966. struct hlist_bl_node *next, **pprev;
  8967. };
  8968. -#define INIT_HLIST_BL_HEAD(ptr) \
  8969. - ((ptr)->first = NULL)
  8970. +
  8971. +static inline void INIT_HLIST_BL_HEAD(struct hlist_bl_head *h)
  8972. +{
  8973. + h->first = NULL;
  8974. +#ifdef CONFIG_PREEMPT_RT_BASE
  8975. + raw_spin_lock_init(&h->lock);
  8976. +#endif
  8977. +}
  8978. static inline void INIT_HLIST_BL_NODE(struct hlist_bl_node *h)
  8979. {
  8980. @@ -117,12 +127,26 @@
  8981. static inline void hlist_bl_lock(struct hlist_bl_head *b)
  8982. {
  8983. +#ifndef CONFIG_PREEMPT_RT_BASE
  8984. bit_spin_lock(0, (unsigned long *)b);
  8985. +#else
  8986. + raw_spin_lock(&b->lock);
  8987. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  8988. + __set_bit(0, (unsigned long *)b);
  8989. +#endif
  8990. +#endif
  8991. }
  8992. static inline void hlist_bl_unlock(struct hlist_bl_head *b)
  8993. {
  8994. +#ifndef CONFIG_PREEMPT_RT_BASE
  8995. __bit_spin_unlock(0, (unsigned long *)b);
  8996. +#else
  8997. +#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
  8998. + __clear_bit(0, (unsigned long *)b);
  8999. +#endif
  9000. + raw_spin_unlock(&b->lock);
  9001. +#endif
  9002. }
  9003. static inline bool hlist_bl_is_locked(struct hlist_bl_head *b)
  9004. diff -Nur linux-4.1.6.orig/include/linux/locallock.h linux-4.1.6/include/linux/locallock.h
  9005. --- linux-4.1.6.orig/include/linux/locallock.h 1970-01-01 01:00:00.000000000 +0100
  9006. +++ linux-4.1.6/include/linux/locallock.h 2015-09-08 23:49:06.550039912 +0200
  9007. @@ -0,0 +1,270 @@
  9008. +#ifndef _LINUX_LOCALLOCK_H
  9009. +#define _LINUX_LOCALLOCK_H
  9010. +
  9011. +#include <linux/percpu.h>
  9012. +#include <linux/spinlock.h>
  9013. +
  9014. +#ifdef CONFIG_PREEMPT_RT_BASE
  9015. +
  9016. +#ifdef CONFIG_DEBUG_SPINLOCK
  9017. +# define LL_WARN(cond) WARN_ON(cond)
  9018. +#else
  9019. +# define LL_WARN(cond) do { } while (0)
  9020. +#endif
  9021. +
  9022. +/*
  9023. + * per cpu lock based substitute for local_irq_*()
  9024. + */
  9025. +struct local_irq_lock {
  9026. + spinlock_t lock;
  9027. + struct task_struct *owner;
  9028. + int nestcnt;
  9029. + unsigned long flags;
  9030. +};
  9031. +
  9032. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) \
  9033. + DEFINE_PER_CPU(struct local_irq_lock, lvar) = { \
  9034. + .lock = __SPIN_LOCK_UNLOCKED((lvar).lock) }
  9035. +
  9036. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) \
  9037. + DECLARE_PER_CPU(struct local_irq_lock, lvar)
  9038. +
  9039. +#define local_irq_lock_init(lvar) \
  9040. + do { \
  9041. + int __cpu; \
  9042. + for_each_possible_cpu(__cpu) \
  9043. + spin_lock_init(&per_cpu(lvar, __cpu).lock); \
  9044. + } while (0)
  9045. +
  9046. +/*
  9047. + * spin_lock|trylock|unlock_local flavour that does not migrate disable
  9048. + * used for __local_lock|trylock|unlock where get_local_var/put_local_var
  9049. + * already takes care of the migrate_disable/enable
  9050. + * for CONFIG_PREEMPT_BASE map to the normal spin_* calls.
  9051. + */
  9052. +#ifdef CONFIG_PREEMPT_RT_FULL
  9053. +# define spin_lock_local(lock) rt_spin_lock(lock)
  9054. +# define spin_trylock_local(lock) rt_spin_trylock(lock)
  9055. +# define spin_unlock_local(lock) rt_spin_unlock(lock)
  9056. +#else
  9057. +# define spin_lock_local(lock) spin_lock(lock)
  9058. +# define spin_trylock_local(lock) spin_trylock(lock)
  9059. +# define spin_unlock_local(lock) spin_unlock(lock)
  9060. +#endif
  9061. +
  9062. +static inline void __local_lock(struct local_irq_lock *lv)
  9063. +{
  9064. + if (lv->owner != current) {
  9065. + spin_lock_local(&lv->lock);
  9066. + LL_WARN(lv->owner);
  9067. + LL_WARN(lv->nestcnt);
  9068. + lv->owner = current;
  9069. + }
  9070. + lv->nestcnt++;
  9071. +}
  9072. +
  9073. +#define local_lock(lvar) \
  9074. + do { __local_lock(&get_local_var(lvar)); } while (0)
  9075. +
  9076. +static inline int __local_trylock(struct local_irq_lock *lv)
  9077. +{
  9078. + if (lv->owner != current && spin_trylock_local(&lv->lock)) {
  9079. + LL_WARN(lv->owner);
  9080. + LL_WARN(lv->nestcnt);
  9081. + lv->owner = current;
  9082. + lv->nestcnt = 1;
  9083. + return 1;
  9084. + }
  9085. + return 0;
  9086. +}
  9087. +
  9088. +#define local_trylock(lvar) \
  9089. + ({ \
  9090. + int __locked; \
  9091. + __locked = __local_trylock(&get_local_var(lvar)); \
  9092. + if (!__locked) \
  9093. + put_local_var(lvar); \
  9094. + __locked; \
  9095. + })
  9096. +
  9097. +static inline void __local_unlock(struct local_irq_lock *lv)
  9098. +{
  9099. + LL_WARN(lv->nestcnt == 0);
  9100. + LL_WARN(lv->owner != current);
  9101. + if (--lv->nestcnt)
  9102. + return;
  9103. +
  9104. + lv->owner = NULL;
  9105. + spin_unlock_local(&lv->lock);
  9106. +}
  9107. +
  9108. +#define local_unlock(lvar) \
  9109. + do { \
  9110. + __local_unlock(this_cpu_ptr(&lvar)); \
  9111. + put_local_var(lvar); \
  9112. + } while (0)
  9113. +
  9114. +static inline void __local_lock_irq(struct local_irq_lock *lv)
  9115. +{
  9116. + spin_lock_irqsave(&lv->lock, lv->flags);
  9117. + LL_WARN(lv->owner);
  9118. + LL_WARN(lv->nestcnt);
  9119. + lv->owner = current;
  9120. + lv->nestcnt = 1;
  9121. +}
  9122. +
  9123. +#define local_lock_irq(lvar) \
  9124. + do { __local_lock_irq(&get_local_var(lvar)); } while (0)
  9125. +
  9126. +#define local_lock_irq_on(lvar, cpu) \
  9127. + do { __local_lock_irq(&per_cpu(lvar, cpu)); } while (0)
  9128. +
  9129. +static inline void __local_unlock_irq(struct local_irq_lock *lv)
  9130. +{
  9131. + LL_WARN(!lv->nestcnt);
  9132. + LL_WARN(lv->owner != current);
  9133. + lv->owner = NULL;
  9134. + lv->nestcnt = 0;
  9135. + spin_unlock_irq(&lv->lock);
  9136. +}
  9137. +
  9138. +#define local_unlock_irq(lvar) \
  9139. + do { \
  9140. + __local_unlock_irq(this_cpu_ptr(&lvar)); \
  9141. + put_local_var(lvar); \
  9142. + } while (0)
  9143. +
  9144. +#define local_unlock_irq_on(lvar, cpu) \
  9145. + do { \
  9146. + __local_unlock_irq(&per_cpu(lvar, cpu)); \
  9147. + } while (0)
  9148. +
  9149. +static inline int __local_lock_irqsave(struct local_irq_lock *lv)
  9150. +{
  9151. + if (lv->owner != current) {
  9152. + __local_lock_irq(lv);
  9153. + return 0;
  9154. + } else {
  9155. + lv->nestcnt++;
  9156. + return 1;
  9157. + }
  9158. +}
  9159. +
  9160. +#define local_lock_irqsave(lvar, _flags) \
  9161. + do { \
  9162. + if (__local_lock_irqsave(&get_local_var(lvar))) \
  9163. + put_local_var(lvar); \
  9164. + _flags = __this_cpu_read(lvar.flags); \
  9165. + } while (0)
  9166. +
  9167. +#define local_lock_irqsave_on(lvar, _flags, cpu) \
  9168. + do { \
  9169. + __local_lock_irqsave(&per_cpu(lvar, cpu)); \
  9170. + _flags = per_cpu(lvar, cpu).flags; \
  9171. + } while (0)
  9172. +
  9173. +static inline int __local_unlock_irqrestore(struct local_irq_lock *lv,
  9174. + unsigned long flags)
  9175. +{
  9176. + LL_WARN(!lv->nestcnt);
  9177. + LL_WARN(lv->owner != current);
  9178. + if (--lv->nestcnt)
  9179. + return 0;
  9180. +
  9181. + lv->owner = NULL;
  9182. + spin_unlock_irqrestore(&lv->lock, lv->flags);
  9183. + return 1;
  9184. +}
  9185. +
  9186. +#define local_unlock_irqrestore(lvar, flags) \
  9187. + do { \
  9188. + if (__local_unlock_irqrestore(this_cpu_ptr(&lvar), flags)) \
  9189. + put_local_var(lvar); \
  9190. + } while (0)
  9191. +
  9192. +#define local_unlock_irqrestore_on(lvar, flags, cpu) \
  9193. + do { \
  9194. + __local_unlock_irqrestore(&per_cpu(lvar, cpu), flags); \
  9195. + } while (0)
  9196. +
  9197. +#define local_spin_trylock_irq(lvar, lock) \
  9198. + ({ \
  9199. + int __locked; \
  9200. + local_lock_irq(lvar); \
  9201. + __locked = spin_trylock(lock); \
  9202. + if (!__locked) \
  9203. + local_unlock_irq(lvar); \
  9204. + __locked; \
  9205. + })
  9206. +
  9207. +#define local_spin_lock_irq(lvar, lock) \
  9208. + do { \
  9209. + local_lock_irq(lvar); \
  9210. + spin_lock(lock); \
  9211. + } while (0)
  9212. +
  9213. +#define local_spin_unlock_irq(lvar, lock) \
  9214. + do { \
  9215. + spin_unlock(lock); \
  9216. + local_unlock_irq(lvar); \
  9217. + } while (0)
  9218. +
  9219. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  9220. + do { \
  9221. + local_lock_irqsave(lvar, flags); \
  9222. + spin_lock(lock); \
  9223. + } while (0)
  9224. +
  9225. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  9226. + do { \
  9227. + spin_unlock(lock); \
  9228. + local_unlock_irqrestore(lvar, flags); \
  9229. + } while (0)
  9230. +
  9231. +#define get_locked_var(lvar, var) \
  9232. + (*({ \
  9233. + local_lock(lvar); \
  9234. + this_cpu_ptr(&var); \
  9235. + }))
  9236. +
  9237. +#define put_locked_var(lvar, var) local_unlock(lvar);
  9238. +
  9239. +#define local_lock_cpu(lvar) \
  9240. + ({ \
  9241. + local_lock(lvar); \
  9242. + smp_processor_id(); \
  9243. + })
  9244. +
  9245. +#define local_unlock_cpu(lvar) local_unlock(lvar)
  9246. +
  9247. +#else /* PREEMPT_RT_BASE */
  9248. +
  9249. +#define DEFINE_LOCAL_IRQ_LOCK(lvar) __typeof__(const int) lvar
  9250. +#define DECLARE_LOCAL_IRQ_LOCK(lvar) extern __typeof__(const int) lvar
  9251. +
  9252. +static inline void local_irq_lock_init(int lvar) { }
  9253. +
  9254. +#define local_lock(lvar) preempt_disable()
  9255. +#define local_unlock(lvar) preempt_enable()
  9256. +#define local_lock_irq(lvar) local_irq_disable()
  9257. +#define local_unlock_irq(lvar) local_irq_enable()
  9258. +#define local_lock_irqsave(lvar, flags) local_irq_save(flags)
  9259. +#define local_unlock_irqrestore(lvar, flags) local_irq_restore(flags)
  9260. +
  9261. +#define local_spin_trylock_irq(lvar, lock) spin_trylock_irq(lock)
  9262. +#define local_spin_lock_irq(lvar, lock) spin_lock_irq(lock)
  9263. +#define local_spin_unlock_irq(lvar, lock) spin_unlock_irq(lock)
  9264. +#define local_spin_lock_irqsave(lvar, lock, flags) \
  9265. + spin_lock_irqsave(lock, flags)
  9266. +#define local_spin_unlock_irqrestore(lvar, lock, flags) \
  9267. + spin_unlock_irqrestore(lock, flags)
  9268. +
  9269. +#define get_locked_var(lvar, var) get_cpu_var(var)
  9270. +#define put_locked_var(lvar, var) put_cpu_var(var)
  9271. +
  9272. +#define local_lock_cpu(lvar) get_cpu()
  9273. +#define local_unlock_cpu(lvar) put_cpu()
  9274. +
  9275. +#endif
  9276. +
  9277. +#endif
  9278. diff -Nur linux-4.1.6.orig/include/linux/mm_types.h linux-4.1.6/include/linux/mm_types.h
  9279. --- linux-4.1.6.orig/include/linux/mm_types.h 2015-08-17 05:52:51.000000000 +0200
  9280. +++ linux-4.1.6/include/linux/mm_types.h 2015-09-08 23:49:06.550039912 +0200
  9281. @@ -11,6 +11,7 @@
  9282. #include <linux/completion.h>
  9283. #include <linux/cpumask.h>
  9284. #include <linux/uprobes.h>
  9285. +#include <linux/rcupdate.h>
  9286. #include <linux/page-flags-layout.h>
  9287. #include <asm/page.h>
  9288. #include <asm/mmu.h>
  9289. @@ -462,6 +463,9 @@
  9290. bool tlb_flush_pending;
  9291. #endif
  9292. struct uprobes_state uprobes_state;
  9293. +#ifdef CONFIG_PREEMPT_RT_BASE
  9294. + struct rcu_head delayed_drop;
  9295. +#endif
  9296. #ifdef CONFIG_X86_INTEL_MPX
  9297. /* address of the bounds directory */
  9298. void __user *bd_addr;
  9299. diff -Nur linux-4.1.6.orig/include/linux/mutex.h linux-4.1.6/include/linux/mutex.h
  9300. --- linux-4.1.6.orig/include/linux/mutex.h 2015-08-17 05:52:51.000000000 +0200
  9301. +++ linux-4.1.6/include/linux/mutex.h 2015-09-08 23:49:06.774015077 +0200
  9302. @@ -19,6 +19,17 @@
  9303. #include <asm/processor.h>
  9304. #include <linux/osq_lock.h>
  9305. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  9306. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  9307. + , .dep_map = { .name = #lockname }
  9308. +#else
  9309. +# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  9310. +#endif
  9311. +
  9312. +#ifdef CONFIG_PREEMPT_RT_FULL
  9313. +# include <linux/mutex_rt.h>
  9314. +#else
  9315. +
  9316. /*
  9317. * Simple, straightforward mutexes with strict semantics:
  9318. *
  9319. @@ -99,13 +110,6 @@
  9320. static inline void mutex_destroy(struct mutex *lock) {}
  9321. #endif
  9322. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  9323. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname) \
  9324. - , .dep_map = { .name = #lockname }
  9325. -#else
  9326. -# define __DEP_MAP_MUTEX_INITIALIZER(lockname)
  9327. -#endif
  9328. -
  9329. #define __MUTEX_INITIALIZER(lockname) \
  9330. { .count = ATOMIC_INIT(1) \
  9331. , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \
  9332. @@ -173,6 +177,8 @@
  9333. extern int mutex_trylock(struct mutex *lock);
  9334. extern void mutex_unlock(struct mutex *lock);
  9335. +#endif /* !PREEMPT_RT_FULL */
  9336. +
  9337. extern int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock);
  9338. #endif /* __LINUX_MUTEX_H */
  9339. diff -Nur linux-4.1.6.orig/include/linux/mutex_rt.h linux-4.1.6/include/linux/mutex_rt.h
  9340. --- linux-4.1.6.orig/include/linux/mutex_rt.h 1970-01-01 01:00:00.000000000 +0100
  9341. +++ linux-4.1.6/include/linux/mutex_rt.h 2015-09-08 23:49:06.774015077 +0200
  9342. @@ -0,0 +1,84 @@
  9343. +#ifndef __LINUX_MUTEX_RT_H
  9344. +#define __LINUX_MUTEX_RT_H
  9345. +
  9346. +#ifndef __LINUX_MUTEX_H
  9347. +#error "Please include mutex.h"
  9348. +#endif
  9349. +
  9350. +#include <linux/rtmutex.h>
  9351. +
  9352. +/* FIXME: Just for __lockfunc */
  9353. +#include <linux/spinlock.h>
  9354. +
  9355. +struct mutex {
  9356. + struct rt_mutex lock;
  9357. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  9358. + struct lockdep_map dep_map;
  9359. +#endif
  9360. +};
  9361. +
  9362. +#define __MUTEX_INITIALIZER(mutexname) \
  9363. + { \
  9364. + .lock = __RT_MUTEX_INITIALIZER(mutexname.lock) \
  9365. + __DEP_MAP_MUTEX_INITIALIZER(mutexname) \
  9366. + }
  9367. +
  9368. +#define DEFINE_MUTEX(mutexname) \
  9369. + struct mutex mutexname = __MUTEX_INITIALIZER(mutexname)
  9370. +
  9371. +extern void __mutex_do_init(struct mutex *lock, const char *name, struct lock_class_key *key);
  9372. +extern void __lockfunc _mutex_lock(struct mutex *lock);
  9373. +extern int __lockfunc _mutex_lock_interruptible(struct mutex *lock);
  9374. +extern int __lockfunc _mutex_lock_killable(struct mutex *lock);
  9375. +extern void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass);
  9376. +extern void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest_lock);
  9377. +extern int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass);
  9378. +extern int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass);
  9379. +extern int __lockfunc _mutex_trylock(struct mutex *lock);
  9380. +extern void __lockfunc _mutex_unlock(struct mutex *lock);
  9381. +
  9382. +#define mutex_is_locked(l) rt_mutex_is_locked(&(l)->lock)
  9383. +#define mutex_lock(l) _mutex_lock(l)
  9384. +#define mutex_lock_interruptible(l) _mutex_lock_interruptible(l)
  9385. +#define mutex_lock_killable(l) _mutex_lock_killable(l)
  9386. +#define mutex_trylock(l) _mutex_trylock(l)
  9387. +#define mutex_unlock(l) _mutex_unlock(l)
  9388. +#define mutex_destroy(l) rt_mutex_destroy(&(l)->lock)
  9389. +
  9390. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  9391. +# define mutex_lock_nested(l, s) _mutex_lock_nested(l, s)
  9392. +# define mutex_lock_interruptible_nested(l, s) \
  9393. + _mutex_lock_interruptible_nested(l, s)
  9394. +# define mutex_lock_killable_nested(l, s) \
  9395. + _mutex_lock_killable_nested(l, s)
  9396. +
  9397. +# define mutex_lock_nest_lock(lock, nest_lock) \
  9398. +do { \
  9399. + typecheck(struct lockdep_map *, &(nest_lock)->dep_map); \
  9400. + _mutex_lock_nest_lock(lock, &(nest_lock)->dep_map); \
  9401. +} while (0)
  9402. +
  9403. +#else
  9404. +# define mutex_lock_nested(l, s) _mutex_lock(l)
  9405. +# define mutex_lock_interruptible_nested(l, s) \
  9406. + _mutex_lock_interruptible(l)
  9407. +# define mutex_lock_killable_nested(l, s) \
  9408. + _mutex_lock_killable(l)
  9409. +# define mutex_lock_nest_lock(lock, nest_lock) mutex_lock(lock)
  9410. +#endif
  9411. +
  9412. +# define mutex_init(mutex) \
  9413. +do { \
  9414. + static struct lock_class_key __key; \
  9415. + \
  9416. + rt_mutex_init(&(mutex)->lock); \
  9417. + __mutex_do_init((mutex), #mutex, &__key); \
  9418. +} while (0)
  9419. +
  9420. +# define __mutex_init(mutex, name, key) \
  9421. +do { \
  9422. + rt_mutex_init(&(mutex)->lock); \
  9423. + __mutex_do_init((mutex), name, key); \
  9424. +} while (0)
  9425. +
  9426. +#endif
  9427. diff -Nur linux-4.1.6.orig/include/linux/netdevice.h linux-4.1.6/include/linux/netdevice.h
  9428. --- linux-4.1.6.orig/include/linux/netdevice.h 2015-08-17 05:52:51.000000000 +0200
  9429. +++ linux-4.1.6/include/linux/netdevice.h 2015-09-08 23:49:06.778014632 +0200
  9430. @@ -2469,6 +2469,7 @@
  9431. unsigned int dropped;
  9432. struct sk_buff_head input_pkt_queue;
  9433. struct napi_struct backlog;
  9434. + struct sk_buff_head tofree_queue;
  9435. };
  9436. diff -Nur linux-4.1.6.orig/include/linux/netfilter/x_tables.h linux-4.1.6/include/linux/netfilter/x_tables.h
  9437. --- linux-4.1.6.orig/include/linux/netfilter/x_tables.h 2015-08-17 05:52:51.000000000 +0200
  9438. +++ linux-4.1.6/include/linux/netfilter/x_tables.h 2015-09-08 23:49:06.778014632 +0200
  9439. @@ -3,6 +3,7 @@
  9440. #include <linux/netdevice.h>
  9441. +#include <linux/locallock.h>
  9442. #include <uapi/linux/netfilter/x_tables.h>
  9443. /**
  9444. @@ -282,6 +283,8 @@
  9445. */
  9446. DECLARE_PER_CPU(seqcount_t, xt_recseq);
  9447. +DECLARE_LOCAL_IRQ_LOCK(xt_write_lock);
  9448. +
  9449. /**
  9450. * xt_write_recseq_begin - start of a write section
  9451. *
  9452. @@ -296,6 +299,9 @@
  9453. {
  9454. unsigned int addend;
  9455. + /* RT protection */
  9456. + local_lock(xt_write_lock);
  9457. +
  9458. /*
  9459. * Low order bit of sequence is set if we already
  9460. * called xt_write_recseq_begin().
  9461. @@ -326,6 +332,7 @@
  9462. /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */
  9463. smp_wmb();
  9464. __this_cpu_add(xt_recseq.sequence, addend);
  9465. + local_unlock(xt_write_lock);
  9466. }
  9467. /*
  9468. diff -Nur linux-4.1.6.orig/include/linux/notifier.h linux-4.1.6/include/linux/notifier.h
  9469. --- linux-4.1.6.orig/include/linux/notifier.h 2015-08-17 05:52:51.000000000 +0200
  9470. +++ linux-4.1.6/include/linux/notifier.h 2015-09-08 23:49:06.778014632 +0200
  9471. @@ -6,7 +6,7 @@
  9472. *
  9473. * Alan Cox <Alan.Cox@linux.org>
  9474. */
  9475. -
  9476. +
  9477. #ifndef _LINUX_NOTIFIER_H
  9478. #define _LINUX_NOTIFIER_H
  9479. #include <linux/errno.h>
  9480. @@ -42,9 +42,7 @@
  9481. * in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
  9482. * As compensation, srcu_notifier_chain_unregister() is rather expensive.
  9483. * SRCU notifier chains should be used when the chain will be called very
  9484. - * often but notifier_blocks will seldom be removed. Also, SRCU notifier
  9485. - * chains are slightly more difficult to use because they require special
  9486. - * runtime initialization.
  9487. + * often but notifier_blocks will seldom be removed.
  9488. */
  9489. typedef int (*notifier_fn_t)(struct notifier_block *nb,
  9490. @@ -88,7 +86,7 @@
  9491. (name)->head = NULL; \
  9492. } while (0)
  9493. -/* srcu_notifier_heads must be initialized and cleaned up dynamically */
  9494. +/* srcu_notifier_heads must be cleaned up dynamically */
  9495. extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
  9496. #define srcu_cleanup_notifier_head(name) \
  9497. cleanup_srcu_struct(&(name)->srcu);
  9498. @@ -101,7 +99,13 @@
  9499. .head = NULL }
  9500. #define RAW_NOTIFIER_INIT(name) { \
  9501. .head = NULL }
  9502. -/* srcu_notifier_heads cannot be initialized statically */
  9503. +
  9504. +#define SRCU_NOTIFIER_INIT(name, pcpu) \
  9505. + { \
  9506. + .mutex = __MUTEX_INITIALIZER(name.mutex), \
  9507. + .head = NULL, \
  9508. + .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
  9509. + }
  9510. #define ATOMIC_NOTIFIER_HEAD(name) \
  9511. struct atomic_notifier_head name = \
  9512. @@ -113,6 +117,18 @@
  9513. struct raw_notifier_head name = \
  9514. RAW_NOTIFIER_INIT(name)
  9515. +#define _SRCU_NOTIFIER_HEAD(name, mod) \
  9516. + static DEFINE_PER_CPU(struct srcu_struct_array, \
  9517. + name##_head_srcu_array); \
  9518. + mod struct srcu_notifier_head name = \
  9519. + SRCU_NOTIFIER_INIT(name, name##_head_srcu_array)
  9520. +
  9521. +#define SRCU_NOTIFIER_HEAD(name) \
  9522. + _SRCU_NOTIFIER_HEAD(name, )
  9523. +
  9524. +#define SRCU_NOTIFIER_HEAD_STATIC(name) \
  9525. + _SRCU_NOTIFIER_HEAD(name, static)
  9526. +
  9527. #ifdef __KERNEL__
  9528. extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
  9529. @@ -182,12 +198,12 @@
  9530. /*
  9531. * Declared notifiers so far. I can imagine quite a few more chains
  9532. - * over time (eg laptop power reset chains, reboot chain (to clean
  9533. + * over time (eg laptop power reset chains, reboot chain (to clean
  9534. * device units up), device [un]mount chain, module load/unload chain,
  9535. - * low memory chain, screenblank chain (for plug in modular screenblankers)
  9536. + * low memory chain, screenblank chain (for plug in modular screenblankers)
  9537. * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
  9538. */
  9539. -
  9540. +
  9541. /* CPU notfiers are defined in include/linux/cpu.h. */
  9542. /* netdevice notifiers are defined in include/linux/netdevice.h */
  9543. diff -Nur linux-4.1.6.orig/include/linux/percpu.h linux-4.1.6/include/linux/percpu.h
  9544. --- linux-4.1.6.orig/include/linux/percpu.h 2015-08-17 05:52:51.000000000 +0200
  9545. +++ linux-4.1.6/include/linux/percpu.h 2015-09-08 23:49:06.778014632 +0200
  9546. @@ -24,6 +24,35 @@
  9547. PERCPU_MODULE_RESERVE)
  9548. #endif
  9549. +#ifdef CONFIG_PREEMPT_RT_FULL
  9550. +
  9551. +#define get_local_var(var) (*({ \
  9552. + migrate_disable(); \
  9553. + this_cpu_ptr(&var); }))
  9554. +
  9555. +#define put_local_var(var) do { \
  9556. + (void)&(var); \
  9557. + migrate_enable(); \
  9558. +} while (0)
  9559. +
  9560. +# define get_local_ptr(var) ({ \
  9561. + migrate_disable(); \
  9562. + this_cpu_ptr(var); })
  9563. +
  9564. +# define put_local_ptr(var) do { \
  9565. + (void)(var); \
  9566. + migrate_enable(); \
  9567. +} while (0)
  9568. +
  9569. +#else
  9570. +
  9571. +#define get_local_var(var) get_cpu_var(var)
  9572. +#define put_local_var(var) put_cpu_var(var)
  9573. +#define get_local_ptr(var) get_cpu_ptr(var)
  9574. +#define put_local_ptr(var) put_cpu_ptr(var)
  9575. +
  9576. +#endif
  9577. +
  9578. /* minimum unit size, also is the maximum supported allocation size */
  9579. #define PCPU_MIN_UNIT_SIZE PFN_ALIGN(32 << 10)
  9580. diff -Nur linux-4.1.6.orig/include/linux/pid.h linux-4.1.6/include/linux/pid.h
  9581. --- linux-4.1.6.orig/include/linux/pid.h 2015-08-17 05:52:51.000000000 +0200
  9582. +++ linux-4.1.6/include/linux/pid.h 2015-09-08 23:49:06.778014632 +0200
  9583. @@ -2,6 +2,7 @@
  9584. #define _LINUX_PID_H
  9585. #include <linux/rcupdate.h>
  9586. +#include <linux/atomic.h>
  9587. enum pid_type
  9588. {
  9589. diff -Nur linux-4.1.6.orig/include/linux/preempt.h linux-4.1.6/include/linux/preempt.h
  9590. --- linux-4.1.6.orig/include/linux/preempt.h 2015-08-17 05:52:51.000000000 +0200
  9591. +++ linux-4.1.6/include/linux/preempt.h 2015-09-08 23:49:06.778014632 +0200
  9592. @@ -33,6 +33,20 @@
  9593. #define preempt_count_inc() preempt_count_add(1)
  9594. #define preempt_count_dec() preempt_count_sub(1)
  9595. +#ifdef CONFIG_PREEMPT_LAZY
  9596. +#define add_preempt_lazy_count(val) do { preempt_lazy_count() += (val); } while (0)
  9597. +#define sub_preempt_lazy_count(val) do { preempt_lazy_count() -= (val); } while (0)
  9598. +#define inc_preempt_lazy_count() add_preempt_lazy_count(1)
  9599. +#define dec_preempt_lazy_count() sub_preempt_lazy_count(1)
  9600. +#define preempt_lazy_count() (current_thread_info()->preempt_lazy_count)
  9601. +#else
  9602. +#define add_preempt_lazy_count(val) do { } while (0)
  9603. +#define sub_preempt_lazy_count(val) do { } while (0)
  9604. +#define inc_preempt_lazy_count() do { } while (0)
  9605. +#define dec_preempt_lazy_count() do { } while (0)
  9606. +#define preempt_lazy_count() (0)
  9607. +#endif
  9608. +
  9609. #ifdef CONFIG_PREEMPT_COUNT
  9610. #define preempt_disable() \
  9611. @@ -41,13 +55,25 @@
  9612. barrier(); \
  9613. } while (0)
  9614. +#define preempt_lazy_disable() \
  9615. +do { \
  9616. + inc_preempt_lazy_count(); \
  9617. + barrier(); \
  9618. +} while (0)
  9619. +
  9620. #define sched_preempt_enable_no_resched() \
  9621. do { \
  9622. barrier(); \
  9623. preempt_count_dec(); \
  9624. } while (0)
  9625. -#define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  9626. +#ifdef CONFIG_PREEMPT_RT_BASE
  9627. +# define preempt_enable_no_resched() sched_preempt_enable_no_resched()
  9628. +# define preempt_check_resched_rt() preempt_check_resched()
  9629. +#else
  9630. +# define preempt_enable_no_resched() preempt_enable()
  9631. +# define preempt_check_resched_rt() barrier();
  9632. +#endif
  9633. #ifdef CONFIG_PREEMPT
  9634. #define preempt_enable() \
  9635. @@ -63,6 +89,13 @@
  9636. __preempt_schedule(); \
  9637. } while (0)
  9638. +#define preempt_lazy_enable() \
  9639. +do { \
  9640. + dec_preempt_lazy_count(); \
  9641. + barrier(); \
  9642. + preempt_check_resched(); \
  9643. +} while (0)
  9644. +
  9645. #else
  9646. #define preempt_enable() \
  9647. do { \
  9648. @@ -121,6 +154,7 @@
  9649. #define preempt_disable_notrace() barrier()
  9650. #define preempt_enable_no_resched_notrace() barrier()
  9651. #define preempt_enable_notrace() barrier()
  9652. +#define preempt_check_resched_rt() barrier()
  9653. #endif /* CONFIG_PREEMPT_COUNT */
  9654. @@ -140,10 +174,31 @@
  9655. } while (0)
  9656. #define preempt_fold_need_resched() \
  9657. do { \
  9658. - if (tif_need_resched()) \
  9659. + if (tif_need_resched_now()) \
  9660. set_preempt_need_resched(); \
  9661. } while (0)
  9662. +#ifdef CONFIG_PREEMPT_RT_FULL
  9663. +# define preempt_disable_rt() preempt_disable()
  9664. +# define preempt_enable_rt() preempt_enable()
  9665. +# define preempt_disable_nort() barrier()
  9666. +# define preempt_enable_nort() barrier()
  9667. +# ifdef CONFIG_SMP
  9668. + extern void migrate_disable(void);
  9669. + extern void migrate_enable(void);
  9670. +# else /* CONFIG_SMP */
  9671. +# define migrate_disable() barrier()
  9672. +# define migrate_enable() barrier()
  9673. +# endif /* CONFIG_SMP */
  9674. +#else
  9675. +# define preempt_disable_rt() barrier()
  9676. +# define preempt_enable_rt() barrier()
  9677. +# define preempt_disable_nort() preempt_disable()
  9678. +# define preempt_enable_nort() preempt_enable()
  9679. +# define migrate_disable() preempt_disable()
  9680. +# define migrate_enable() preempt_enable()
  9681. +#endif
  9682. +
  9683. #ifdef CONFIG_PREEMPT_NOTIFIERS
  9684. struct preempt_notifier;
  9685. diff -Nur linux-4.1.6.orig/include/linux/preempt_mask.h linux-4.1.6/include/linux/preempt_mask.h
  9686. --- linux-4.1.6.orig/include/linux/preempt_mask.h 2015-08-17 05:52:51.000000000 +0200
  9687. +++ linux-4.1.6/include/linux/preempt_mask.h 2015-09-08 23:49:06.778014632 +0200
  9688. @@ -44,16 +44,26 @@
  9689. #define HARDIRQ_OFFSET (1UL << HARDIRQ_SHIFT)
  9690. #define NMI_OFFSET (1UL << NMI_SHIFT)
  9691. -#define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  9692. +#ifndef CONFIG_PREEMPT_RT_FULL
  9693. +# define SOFTIRQ_DISABLE_OFFSET (2 * SOFTIRQ_OFFSET)
  9694. +#else
  9695. +# define SOFTIRQ_DISABLE_OFFSET (0)
  9696. +#endif
  9697. #define PREEMPT_ACTIVE_BITS 1
  9698. #define PREEMPT_ACTIVE_SHIFT (NMI_SHIFT + NMI_BITS)
  9699. #define PREEMPT_ACTIVE (__IRQ_MASK(PREEMPT_ACTIVE_BITS) << PREEMPT_ACTIVE_SHIFT)
  9700. #define hardirq_count() (preempt_count() & HARDIRQ_MASK)
  9701. -#define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  9702. #define irq_count() (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_MASK \
  9703. | NMI_MASK))
  9704. +#ifndef CONFIG_PREEMPT_RT_FULL
  9705. +# define softirq_count() (preempt_count() & SOFTIRQ_MASK)
  9706. +# define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  9707. +#else
  9708. +# define softirq_count() (0UL)
  9709. +extern int in_serving_softirq(void);
  9710. +#endif
  9711. /*
  9712. * Are we doing bottom half or hardware interrupt processing?
  9713. @@ -64,7 +74,6 @@
  9714. #define in_irq() (hardirq_count())
  9715. #define in_softirq() (softirq_count())
  9716. #define in_interrupt() (irq_count())
  9717. -#define in_serving_softirq() (softirq_count() & SOFTIRQ_OFFSET)
  9718. /*
  9719. * Are we in NMI context?
  9720. diff -Nur linux-4.1.6.orig/include/linux/printk.h linux-4.1.6/include/linux/printk.h
  9721. --- linux-4.1.6.orig/include/linux/printk.h 2015-08-17 05:52:51.000000000 +0200
  9722. +++ linux-4.1.6/include/linux/printk.h 2015-09-08 23:49:06.778014632 +0200
  9723. @@ -115,9 +115,11 @@
  9724. #ifdef CONFIG_EARLY_PRINTK
  9725. extern asmlinkage __printf(1, 2)
  9726. void early_printk(const char *fmt, ...);
  9727. +extern void printk_kill(void);
  9728. #else
  9729. static inline __printf(1, 2) __cold
  9730. void early_printk(const char *s, ...) { }
  9731. +static inline void printk_kill(void) { }
  9732. #endif
  9733. typedef int(*printk_func_t)(const char *fmt, va_list args);
  9734. diff -Nur linux-4.1.6.orig/include/linux/radix-tree.h linux-4.1.6/include/linux/radix-tree.h
  9735. --- linux-4.1.6.orig/include/linux/radix-tree.h 2015-08-17 05:52:51.000000000 +0200
  9736. +++ linux-4.1.6/include/linux/radix-tree.h 2015-09-08 23:49:06.778014632 +0200
  9737. @@ -277,8 +277,13 @@
  9738. unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root,
  9739. void ***results, unsigned long *indices,
  9740. unsigned long first_index, unsigned int max_items);
  9741. +#ifndef CONFIG_PREEMPT_RT_FULL
  9742. int radix_tree_preload(gfp_t gfp_mask);
  9743. int radix_tree_maybe_preload(gfp_t gfp_mask);
  9744. +#else
  9745. +static inline int radix_tree_preload(gfp_t gm) { return 0; }
  9746. +static inline int radix_tree_maybe_preload(gfp_t gfp_mask) { return 0; }
  9747. +#endif
  9748. void radix_tree_init(void);
  9749. void *radix_tree_tag_set(struct radix_tree_root *root,
  9750. unsigned long index, unsigned int tag);
  9751. @@ -303,7 +308,7 @@
  9752. static inline void radix_tree_preload_end(void)
  9753. {
  9754. - preempt_enable();
  9755. + preempt_enable_nort();
  9756. }
  9757. /**
  9758. diff -Nur linux-4.1.6.orig/include/linux/random.h linux-4.1.6/include/linux/random.h
  9759. --- linux-4.1.6.orig/include/linux/random.h 2015-08-17 05:52:51.000000000 +0200
  9760. +++ linux-4.1.6/include/linux/random.h 2015-09-08 23:49:06.778014632 +0200
  9761. @@ -11,7 +11,7 @@
  9762. extern void add_device_randomness(const void *, unsigned int);
  9763. extern void add_input_randomness(unsigned int type, unsigned int code,
  9764. unsigned int value);
  9765. -extern void add_interrupt_randomness(int irq, int irq_flags);
  9766. +extern void add_interrupt_randomness(int irq, int irq_flags, __u64 ip);
  9767. extern void get_random_bytes(void *buf, int nbytes);
  9768. extern void get_random_bytes_arch(void *buf, int nbytes);
  9769. diff -Nur linux-4.1.6.orig/include/linux/rcupdate.h linux-4.1.6/include/linux/rcupdate.h
  9770. --- linux-4.1.6.orig/include/linux/rcupdate.h 2015-08-17 05:52:51.000000000 +0200
  9771. +++ linux-4.1.6/include/linux/rcupdate.h 2015-09-08 23:49:06.778014632 +0200
  9772. @@ -167,6 +167,9 @@
  9773. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  9774. +#ifdef CONFIG_PREEMPT_RT_FULL
  9775. +#define call_rcu_bh call_rcu
  9776. +#else
  9777. /**
  9778. * call_rcu_bh() - Queue an RCU for invocation after a quicker grace period.
  9779. * @head: structure to be used for queueing the RCU updates.
  9780. @@ -190,6 +193,7 @@
  9781. */
  9782. void call_rcu_bh(struct rcu_head *head,
  9783. void (*func)(struct rcu_head *head));
  9784. +#endif
  9785. /**
  9786. * call_rcu_sched() - Queue an RCU for invocation after sched grace period.
  9787. @@ -260,6 +264,11 @@
  9788. * types of kernel builds, the rcu_read_lock() nesting depth is unknowable.
  9789. */
  9790. #define rcu_preempt_depth() (current->rcu_read_lock_nesting)
  9791. +#ifndef CONFIG_PREEMPT_RT_FULL
  9792. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  9793. +#else
  9794. +static inline int sched_rcu_preempt_depth(void) { return 0; }
  9795. +#endif
  9796. #else /* #ifdef CONFIG_PREEMPT_RCU */
  9797. @@ -283,6 +292,8 @@
  9798. return 0;
  9799. }
  9800. +#define sched_rcu_preempt_depth() rcu_preempt_depth()
  9801. +
  9802. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  9803. /* Internal to kernel */
  9804. @@ -463,7 +474,14 @@
  9805. int debug_lockdep_rcu_enabled(void);
  9806. int rcu_read_lock_held(void);
  9807. +#ifdef CONFIG_PREEMPT_RT_FULL
  9808. +static inline int rcu_read_lock_bh_held(void)
  9809. +{
  9810. + return rcu_read_lock_held();
  9811. +}
  9812. +#else
  9813. int rcu_read_lock_bh_held(void);
  9814. +#endif
  9815. /**
  9816. * rcu_read_lock_sched_held() - might we be in RCU-sched read-side critical section?
  9817. @@ -990,10 +1008,14 @@
  9818. static inline void rcu_read_lock_bh(void)
  9819. {
  9820. local_bh_disable();
  9821. +#ifdef CONFIG_PREEMPT_RT_FULL
  9822. + rcu_read_lock();
  9823. +#else
  9824. __acquire(RCU_BH);
  9825. rcu_lock_acquire(&rcu_bh_lock_map);
  9826. rcu_lockdep_assert(rcu_is_watching(),
  9827. "rcu_read_lock_bh() used illegally while idle");
  9828. +#endif
  9829. }
  9830. /*
  9831. @@ -1003,10 +1025,14 @@
  9832. */
  9833. static inline void rcu_read_unlock_bh(void)
  9834. {
  9835. +#ifdef CONFIG_PREEMPT_RT_FULL
  9836. + rcu_read_unlock();
  9837. +#else
  9838. rcu_lockdep_assert(rcu_is_watching(),
  9839. "rcu_read_unlock_bh() used illegally while idle");
  9840. rcu_lock_release(&rcu_bh_lock_map);
  9841. __release(RCU_BH);
  9842. +#endif
  9843. local_bh_enable();
  9844. }
  9845. diff -Nur linux-4.1.6.orig/include/linux/rcutree.h linux-4.1.6/include/linux/rcutree.h
  9846. --- linux-4.1.6.orig/include/linux/rcutree.h 2015-08-17 05:52:51.000000000 +0200
  9847. +++ linux-4.1.6/include/linux/rcutree.h 2015-09-08 23:49:06.778014632 +0200
  9848. @@ -46,7 +46,11 @@
  9849. rcu_note_context_switch();
  9850. }
  9851. +#ifdef CONFIG_PREEMPT_RT_FULL
  9852. +# define synchronize_rcu_bh synchronize_rcu
  9853. +#else
  9854. void synchronize_rcu_bh(void);
  9855. +#endif
  9856. void synchronize_sched_expedited(void);
  9857. void synchronize_rcu_expedited(void);
  9858. @@ -74,7 +78,11 @@
  9859. }
  9860. void rcu_barrier(void);
  9861. +#ifdef CONFIG_PREEMPT_RT_FULL
  9862. +# define rcu_barrier_bh rcu_barrier
  9863. +#else
  9864. void rcu_barrier_bh(void);
  9865. +#endif
  9866. void rcu_barrier_sched(void);
  9867. unsigned long get_state_synchronize_rcu(void);
  9868. void cond_synchronize_rcu(unsigned long oldstate);
  9869. @@ -85,12 +93,10 @@
  9870. unsigned long rcu_batches_started_bh(void);
  9871. unsigned long rcu_batches_started_sched(void);
  9872. unsigned long rcu_batches_completed(void);
  9873. -unsigned long rcu_batches_completed_bh(void);
  9874. unsigned long rcu_batches_completed_sched(void);
  9875. void show_rcu_gp_kthreads(void);
  9876. void rcu_force_quiescent_state(void);
  9877. -void rcu_bh_force_quiescent_state(void);
  9878. void rcu_sched_force_quiescent_state(void);
  9879. void exit_rcu(void);
  9880. @@ -100,6 +106,14 @@
  9881. bool rcu_is_watching(void);
  9882. +#ifndef CONFIG_PREEMPT_RT_FULL
  9883. +void rcu_bh_force_quiescent_state(void);
  9884. +unsigned long rcu_batches_completed_bh(void);
  9885. +#else
  9886. +# define rcu_bh_force_quiescent_state rcu_force_quiescent_state
  9887. +# define rcu_batches_completed_bh rcu_batches_completed
  9888. +#endif
  9889. +
  9890. void rcu_all_qs(void);
  9891. #endif /* __LINUX_RCUTREE_H */
  9892. diff -Nur linux-4.1.6.orig/include/linux/rtmutex.h linux-4.1.6/include/linux/rtmutex.h
  9893. --- linux-4.1.6.orig/include/linux/rtmutex.h 2015-08-17 05:52:51.000000000 +0200
  9894. +++ linux-4.1.6/include/linux/rtmutex.h 2015-09-08 23:49:06.778014632 +0200
  9895. @@ -14,10 +14,14 @@
  9896. #include <linux/linkage.h>
  9897. #include <linux/rbtree.h>
  9898. -#include <linux/spinlock_types.h>
  9899. +#include <linux/spinlock_types_raw.h>
  9900. extern int max_lock_depth; /* for sysctl */
  9901. +#ifdef CONFIG_DEBUG_MUTEXES
  9902. +#include <linux/debug_locks.h>
  9903. +#endif
  9904. +
  9905. /**
  9906. * The rt_mutex structure
  9907. *
  9908. @@ -31,8 +35,8 @@
  9909. struct rb_root waiters;
  9910. struct rb_node *waiters_leftmost;
  9911. struct task_struct *owner;
  9912. -#ifdef CONFIG_DEBUG_RT_MUTEXES
  9913. int save_state;
  9914. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  9915. const char *name, *file;
  9916. int line;
  9917. void *magic;
  9918. @@ -55,22 +59,33 @@
  9919. # define rt_mutex_debug_check_no_locks_held(task) do { } while (0)
  9920. #endif
  9921. +# define rt_mutex_init(mutex) \
  9922. + do { \
  9923. + raw_spin_lock_init(&(mutex)->wait_lock); \
  9924. + __rt_mutex_init(mutex, #mutex); \
  9925. + } while (0)
  9926. +
  9927. #ifdef CONFIG_DEBUG_RT_MUTEXES
  9928. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname) \
  9929. , .name = #mutexname, .file = __FILE__, .line = __LINE__
  9930. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, __func__)
  9931. extern void rt_mutex_debug_task_free(struct task_struct *tsk);
  9932. #else
  9933. # define __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  9934. -# define rt_mutex_init(mutex) __rt_mutex_init(mutex, NULL)
  9935. # define rt_mutex_debug_task_free(t) do { } while (0)
  9936. #endif
  9937. -#define __RT_MUTEX_INITIALIZER(mutexname) \
  9938. - { .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  9939. +#define __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  9940. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(mutexname.wait_lock) \
  9941. , .waiters = RB_ROOT \
  9942. , .owner = NULL \
  9943. - __DEBUG_RT_MUTEX_INITIALIZER(mutexname)}
  9944. + __DEBUG_RT_MUTEX_INITIALIZER(mutexname)
  9945. +
  9946. +#define __RT_MUTEX_INITIALIZER(mutexname) \
  9947. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) }
  9948. +
  9949. +#define __RT_MUTEX_INITIALIZER_SAVE_STATE(mutexname) \
  9950. + { __RT_MUTEX_INITIALIZER_PLAIN(mutexname) \
  9951. + , .save_state = 1 }
  9952. #define DEFINE_RT_MUTEX(mutexname) \
  9953. struct rt_mutex mutexname = __RT_MUTEX_INITIALIZER(mutexname)
  9954. @@ -91,6 +106,7 @@
  9955. extern void rt_mutex_lock(struct rt_mutex *lock);
  9956. extern int rt_mutex_lock_interruptible(struct rt_mutex *lock);
  9957. +extern int rt_mutex_lock_killable(struct rt_mutex *lock);
  9958. extern int rt_mutex_timed_lock(struct rt_mutex *lock,
  9959. struct hrtimer_sleeper *timeout);
  9960. diff -Nur linux-4.1.6.orig/include/linux/rwlock_rt.h linux-4.1.6/include/linux/rwlock_rt.h
  9961. --- linux-4.1.6.orig/include/linux/rwlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  9962. +++ linux-4.1.6/include/linux/rwlock_rt.h 2015-09-08 23:49:06.778014632 +0200
  9963. @@ -0,0 +1,99 @@
  9964. +#ifndef __LINUX_RWLOCK_RT_H
  9965. +#define __LINUX_RWLOCK_RT_H
  9966. +
  9967. +#ifndef __LINUX_SPINLOCK_H
  9968. +#error Do not include directly. Use spinlock.h
  9969. +#endif
  9970. +
  9971. +#define rwlock_init(rwl) \
  9972. +do { \
  9973. + static struct lock_class_key __key; \
  9974. + \
  9975. + rt_mutex_init(&(rwl)->lock); \
  9976. + __rt_rwlock_init(rwl, #rwl, &__key); \
  9977. +} while (0)
  9978. +
  9979. +extern void __lockfunc rt_write_lock(rwlock_t *rwlock);
  9980. +extern void __lockfunc rt_read_lock(rwlock_t *rwlock);
  9981. +extern int __lockfunc rt_write_trylock(rwlock_t *rwlock);
  9982. +extern int __lockfunc rt_write_trylock_irqsave(rwlock_t *trylock, unsigned long *flags);
  9983. +extern int __lockfunc rt_read_trylock(rwlock_t *rwlock);
  9984. +extern void __lockfunc rt_write_unlock(rwlock_t *rwlock);
  9985. +extern void __lockfunc rt_read_unlock(rwlock_t *rwlock);
  9986. +extern unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock);
  9987. +extern unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock);
  9988. +extern void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key);
  9989. +
  9990. +#define read_trylock(lock) __cond_lock(lock, rt_read_trylock(lock))
  9991. +#define write_trylock(lock) __cond_lock(lock, rt_write_trylock(lock))
  9992. +
  9993. +#define write_trylock_irqsave(lock, flags) \
  9994. + __cond_lock(lock, rt_write_trylock_irqsave(lock, &flags))
  9995. +
  9996. +#define read_lock_irqsave(lock, flags) \
  9997. + do { \
  9998. + typecheck(unsigned long, flags); \
  9999. + flags = rt_read_lock_irqsave(lock); \
  10000. + } while (0)
  10001. +
  10002. +#define write_lock_irqsave(lock, flags) \
  10003. + do { \
  10004. + typecheck(unsigned long, flags); \
  10005. + flags = rt_write_lock_irqsave(lock); \
  10006. + } while (0)
  10007. +
  10008. +#define read_lock(lock) rt_read_lock(lock)
  10009. +
  10010. +#define read_lock_bh(lock) \
  10011. + do { \
  10012. + local_bh_disable(); \
  10013. + rt_read_lock(lock); \
  10014. + } while (0)
  10015. +
  10016. +#define read_lock_irq(lock) read_lock(lock)
  10017. +
  10018. +#define write_lock(lock) rt_write_lock(lock)
  10019. +
  10020. +#define write_lock_bh(lock) \
  10021. + do { \
  10022. + local_bh_disable(); \
  10023. + rt_write_lock(lock); \
  10024. + } while (0)
  10025. +
  10026. +#define write_lock_irq(lock) write_lock(lock)
  10027. +
  10028. +#define read_unlock(lock) rt_read_unlock(lock)
  10029. +
  10030. +#define read_unlock_bh(lock) \
  10031. + do { \
  10032. + rt_read_unlock(lock); \
  10033. + local_bh_enable(); \
  10034. + } while (0)
  10035. +
  10036. +#define read_unlock_irq(lock) read_unlock(lock)
  10037. +
  10038. +#define write_unlock(lock) rt_write_unlock(lock)
  10039. +
  10040. +#define write_unlock_bh(lock) \
  10041. + do { \
  10042. + rt_write_unlock(lock); \
  10043. + local_bh_enable(); \
  10044. + } while (0)
  10045. +
  10046. +#define write_unlock_irq(lock) write_unlock(lock)
  10047. +
  10048. +#define read_unlock_irqrestore(lock, flags) \
  10049. + do { \
  10050. + typecheck(unsigned long, flags); \
  10051. + (void) flags; \
  10052. + rt_read_unlock(lock); \
  10053. + } while (0)
  10054. +
  10055. +#define write_unlock_irqrestore(lock, flags) \
  10056. + do { \
  10057. + typecheck(unsigned long, flags); \
  10058. + (void) flags; \
  10059. + rt_write_unlock(lock); \
  10060. + } while (0)
  10061. +
  10062. +#endif
  10063. diff -Nur linux-4.1.6.orig/include/linux/rwlock_types.h linux-4.1.6/include/linux/rwlock_types.h
  10064. --- linux-4.1.6.orig/include/linux/rwlock_types.h 2015-08-17 05:52:51.000000000 +0200
  10065. +++ linux-4.1.6/include/linux/rwlock_types.h 2015-09-08 23:49:06.778014632 +0200
  10066. @@ -1,6 +1,10 @@
  10067. #ifndef __LINUX_RWLOCK_TYPES_H
  10068. #define __LINUX_RWLOCK_TYPES_H
  10069. +#if !defined(__LINUX_SPINLOCK_TYPES_H)
  10070. +# error "Do not include directly, include spinlock_types.h"
  10071. +#endif
  10072. +
  10073. /*
  10074. * include/linux/rwlock_types.h - generic rwlock type definitions
  10075. * and initializers
  10076. @@ -43,6 +47,7 @@
  10077. RW_DEP_MAP_INIT(lockname) }
  10078. #endif
  10079. -#define DEFINE_RWLOCK(x) rwlock_t x = __RW_LOCK_UNLOCKED(x)
  10080. +#define DEFINE_RWLOCK(name) \
  10081. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  10082. #endif /* __LINUX_RWLOCK_TYPES_H */
  10083. diff -Nur linux-4.1.6.orig/include/linux/rwlock_types_rt.h linux-4.1.6/include/linux/rwlock_types_rt.h
  10084. --- linux-4.1.6.orig/include/linux/rwlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  10085. +++ linux-4.1.6/include/linux/rwlock_types_rt.h 2015-09-08 23:49:06.778014632 +0200
  10086. @@ -0,0 +1,33 @@
  10087. +#ifndef __LINUX_RWLOCK_TYPES_RT_H
  10088. +#define __LINUX_RWLOCK_TYPES_RT_H
  10089. +
  10090. +#ifndef __LINUX_SPINLOCK_TYPES_H
  10091. +#error "Do not include directly. Include spinlock_types.h instead"
  10092. +#endif
  10093. +
  10094. +/*
  10095. + * rwlocks - rtmutex which allows single reader recursion
  10096. + */
  10097. +typedef struct {
  10098. + struct rt_mutex lock;
  10099. + int read_depth;
  10100. + unsigned int break_lock;
  10101. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10102. + struct lockdep_map dep_map;
  10103. +#endif
  10104. +} rwlock_t;
  10105. +
  10106. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10107. +# define RW_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  10108. +#else
  10109. +# define RW_DEP_MAP_INIT(lockname)
  10110. +#endif
  10111. +
  10112. +#define __RW_LOCK_UNLOCKED(name) \
  10113. + { .lock = __RT_MUTEX_INITIALIZER_SAVE_STATE(name.lock), \
  10114. + RW_DEP_MAP_INIT(name) }
  10115. +
  10116. +#define DEFINE_RWLOCK(name) \
  10117. + rwlock_t name __cacheline_aligned_in_smp = __RW_LOCK_UNLOCKED(name)
  10118. +
  10119. +#endif
  10120. diff -Nur linux-4.1.6.orig/include/linux/rwsem.h linux-4.1.6/include/linux/rwsem.h
  10121. --- linux-4.1.6.orig/include/linux/rwsem.h 2015-08-17 05:52:51.000000000 +0200
  10122. +++ linux-4.1.6/include/linux/rwsem.h 2015-09-08 23:49:06.778014632 +0200
  10123. @@ -18,6 +18,10 @@
  10124. #include <linux/osq_lock.h>
  10125. #endif
  10126. +#ifdef CONFIG_PREEMPT_RT_FULL
  10127. +#include <linux/rwsem_rt.h>
  10128. +#else /* PREEMPT_RT_FULL */
  10129. +
  10130. struct rw_semaphore;
  10131. #ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  10132. @@ -177,4 +181,6 @@
  10133. # define up_read_non_owner(sem) up_read(sem)
  10134. #endif
  10135. +#endif /* !PREEMPT_RT_FULL */
  10136. +
  10137. #endif /* _LINUX_RWSEM_H */
  10138. diff -Nur linux-4.1.6.orig/include/linux/rwsem_rt.h linux-4.1.6/include/linux/rwsem_rt.h
  10139. --- linux-4.1.6.orig/include/linux/rwsem_rt.h 1970-01-01 01:00:00.000000000 +0100
  10140. +++ linux-4.1.6/include/linux/rwsem_rt.h 2015-09-08 23:49:06.778014632 +0200
  10141. @@ -0,0 +1,140 @@
  10142. +#ifndef _LINUX_RWSEM_RT_H
  10143. +#define _LINUX_RWSEM_RT_H
  10144. +
  10145. +#ifndef _LINUX_RWSEM_H
  10146. +#error "Include rwsem.h"
  10147. +#endif
  10148. +
  10149. +/*
  10150. + * RW-semaphores are a spinlock plus a reader-depth count.
  10151. + *
  10152. + * Note that the semantics are different from the usual
  10153. + * Linux rw-sems, in PREEMPT_RT mode we do not allow
  10154. + * multiple readers to hold the lock at once, we only allow
  10155. + * a read-lock owner to read-lock recursively. This is
  10156. + * better for latency, makes the implementation inherently
  10157. + * fair and makes it simpler as well.
  10158. + */
  10159. +
  10160. +#include <linux/rtmutex.h>
  10161. +
  10162. +struct rw_semaphore {
  10163. + struct rt_mutex lock;
  10164. + int read_depth;
  10165. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10166. + struct lockdep_map dep_map;
  10167. +#endif
  10168. +};
  10169. +
  10170. +#define __RWSEM_INITIALIZER(name) \
  10171. + { .lock = __RT_MUTEX_INITIALIZER(name.lock), \
  10172. + RW_DEP_MAP_INIT(name) }
  10173. +
  10174. +#define DECLARE_RWSEM(lockname) \
  10175. + struct rw_semaphore lockname = __RWSEM_INITIALIZER(lockname)
  10176. +
  10177. +extern void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  10178. + struct lock_class_key *key);
  10179. +
  10180. +#define __rt_init_rwsem(sem, name, key) \
  10181. + do { \
  10182. + rt_mutex_init(&(sem)->lock); \
  10183. + __rt_rwsem_init((sem), (name), (key));\
  10184. + } while (0)
  10185. +
  10186. +#define __init_rwsem(sem, name, key) __rt_init_rwsem(sem, name, key)
  10187. +
  10188. +# define rt_init_rwsem(sem) \
  10189. +do { \
  10190. + static struct lock_class_key __key; \
  10191. + \
  10192. + __rt_init_rwsem((sem), #sem, &__key); \
  10193. +} while (0)
  10194. +
  10195. +extern void rt_down_write(struct rw_semaphore *rwsem);
  10196. +extern void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass);
  10197. +extern void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass);
  10198. +extern void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  10199. + struct lockdep_map *nest);
  10200. +extern void rt_down_read(struct rw_semaphore *rwsem);
  10201. +extern int rt_down_write_trylock(struct rw_semaphore *rwsem);
  10202. +extern int rt_down_read_trylock(struct rw_semaphore *rwsem);
  10203. +extern void __rt_up_read(struct rw_semaphore *rwsem);
  10204. +extern void rt_up_read(struct rw_semaphore *rwsem);
  10205. +extern void rt_up_write(struct rw_semaphore *rwsem);
  10206. +extern void rt_downgrade_write(struct rw_semaphore *rwsem);
  10207. +
  10208. +#define init_rwsem(sem) rt_init_rwsem(sem)
  10209. +#define rwsem_is_locked(s) rt_mutex_is_locked(&(s)->lock)
  10210. +
  10211. +static inline int rwsem_is_contended(struct rw_semaphore *sem)
  10212. +{
  10213. + /* rt_mutex_has_waiters() */
  10214. + return !RB_EMPTY_ROOT(&sem->lock.waiters);
  10215. +}
  10216. +
  10217. +static inline void down_read(struct rw_semaphore *sem)
  10218. +{
  10219. + rt_down_read(sem);
  10220. +}
  10221. +
  10222. +static inline int down_read_trylock(struct rw_semaphore *sem)
  10223. +{
  10224. + return rt_down_read_trylock(sem);
  10225. +}
  10226. +
  10227. +static inline void down_write(struct rw_semaphore *sem)
  10228. +{
  10229. + rt_down_write(sem);
  10230. +}
  10231. +
  10232. +static inline int down_write_trylock(struct rw_semaphore *sem)
  10233. +{
  10234. + return rt_down_write_trylock(sem);
  10235. +}
  10236. +
  10237. +static inline void __up_read(struct rw_semaphore *sem)
  10238. +{
  10239. + __rt_up_read(sem);
  10240. +}
  10241. +
  10242. +static inline void up_read(struct rw_semaphore *sem)
  10243. +{
  10244. + rt_up_read(sem);
  10245. +}
  10246. +
  10247. +static inline void up_write(struct rw_semaphore *sem)
  10248. +{
  10249. + rt_up_write(sem);
  10250. +}
  10251. +
  10252. +static inline void downgrade_write(struct rw_semaphore *sem)
  10253. +{
  10254. + rt_downgrade_write(sem);
  10255. +}
  10256. +
  10257. +static inline void down_read_nested(struct rw_semaphore *sem, int subclass)
  10258. +{
  10259. + return rt_down_read_nested(sem, subclass);
  10260. +}
  10261. +
  10262. +static inline void down_write_nested(struct rw_semaphore *sem, int subclass)
  10263. +{
  10264. + rt_down_write_nested(sem, subclass);
  10265. +}
  10266. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  10267. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  10268. + struct rw_semaphore *nest_lock)
  10269. +{
  10270. + rt_down_write_nested_lock(sem, &nest_lock->dep_map);
  10271. +}
  10272. +
  10273. +#else
  10274. +
  10275. +static inline void down_write_nest_lock(struct rw_semaphore *sem,
  10276. + struct rw_semaphore *nest_lock)
  10277. +{
  10278. + rt_down_write_nested_lock(sem, NULL);
  10279. +}
  10280. +#endif
  10281. +#endif
  10282. diff -Nur linux-4.1.6.orig/include/linux/sched.h linux-4.1.6/include/linux/sched.h
  10283. --- linux-4.1.6.orig/include/linux/sched.h 2015-08-17 05:52:51.000000000 +0200
  10284. +++ linux-4.1.6/include/linux/sched.h 2015-09-08 23:49:06.778014632 +0200
  10285. @@ -26,6 +26,7 @@
  10286. #include <linux/nodemask.h>
  10287. #include <linux/mm_types.h>
  10288. #include <linux/preempt_mask.h>
  10289. +#include <asm/kmap_types.h>
  10290. #include <asm/page.h>
  10291. #include <asm/ptrace.h>
  10292. @@ -234,10 +235,7 @@
  10293. TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
  10294. __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)
  10295. -#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
  10296. #define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
  10297. -#define task_is_stopped_or_traced(task) \
  10298. - ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
  10299. #define task_contributes_to_load(task) \
  10300. ((task->state & TASK_UNINTERRUPTIBLE) != 0 && \
  10301. (task->flags & PF_FROZEN) == 0)
  10302. @@ -302,6 +300,11 @@
  10303. #endif
  10304. +#define __set_current_state_no_track(state_value) \
  10305. + do { current->state = (state_value); } while (0)
  10306. +#define set_current_state_no_track(state_value) \
  10307. + set_mb(current->state, (state_value))
  10308. +
  10309. /* Task command name length */
  10310. #define TASK_COMM_LEN 16
  10311. @@ -900,6 +903,50 @@
  10312. #define SCHED_CAPACITY_SCALE (1L << SCHED_CAPACITY_SHIFT)
  10313. /*
  10314. + * Wake-queues are lists of tasks with a pending wakeup, whose
  10315. + * callers have already marked the task as woken internally,
  10316. + * and can thus carry on. A common use case is being able to
  10317. + * do the wakeups once the corresponding user lock as been
  10318. + * released.
  10319. + *
  10320. + * We hold reference to each task in the list across the wakeup,
  10321. + * thus guaranteeing that the memory is still valid by the time
  10322. + * the actual wakeups are performed in wake_up_q().
  10323. + *
  10324. + * One per task suffices, because there's never a need for a task to be
  10325. + * in two wake queues simultaneously; it is forbidden to abandon a task
  10326. + * in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
  10327. + * already in a wake queue, the wakeup will happen soon and the second
  10328. + * waker can just skip it.
  10329. + *
  10330. + * The WAKE_Q macro declares and initializes the list head.
  10331. + * wake_up_q() does NOT reinitialize the list; it's expected to be
  10332. + * called near the end of a function, where the fact that the queue is
  10333. + * not used again will be easy to see by inspection.
  10334. + *
  10335. + * Note that this can cause spurious wakeups. schedule() callers
  10336. + * must ensure the call is done inside a loop, confirming that the
  10337. + * wakeup condition has in fact occurred.
  10338. + */
  10339. +struct wake_q_node {
  10340. + struct wake_q_node *next;
  10341. +};
  10342. +
  10343. +struct wake_q_head {
  10344. + struct wake_q_node *first;
  10345. + struct wake_q_node **lastp;
  10346. +};
  10347. +
  10348. +#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
  10349. +
  10350. +#define WAKE_Q(name) \
  10351. + struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
  10352. +
  10353. +extern void wake_q_add(struct wake_q_head *head,
  10354. + struct task_struct *task);
  10355. +extern void wake_up_q(struct wake_q_head *head);
  10356. +
  10357. +/*
  10358. * sched-domains (multiprocessor balancing) declarations:
  10359. */
  10360. #ifdef CONFIG_SMP
  10361. @@ -1291,6 +1338,7 @@
  10362. struct task_struct {
  10363. volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
  10364. + volatile long saved_state; /* saved state for "spinlock sleepers" */
  10365. void *stack;
  10366. atomic_t usage;
  10367. unsigned int flags; /* per process flags, defined below */
  10368. @@ -1327,6 +1375,12 @@
  10369. #endif
  10370. unsigned int policy;
  10371. +#ifdef CONFIG_PREEMPT_RT_FULL
  10372. + int migrate_disable;
  10373. +# ifdef CONFIG_SCHED_DEBUG
  10374. + int migrate_disable_atomic;
  10375. +# endif
  10376. +#endif
  10377. int nr_cpus_allowed;
  10378. cpumask_t cpus_allowed;
  10379. @@ -1434,7 +1488,8 @@
  10380. struct cputime prev_cputime;
  10381. #endif
  10382. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  10383. - seqlock_t vtime_seqlock;
  10384. + raw_spinlock_t vtime_lock;
  10385. + seqcount_t vtime_seq;
  10386. unsigned long long vtime_snap;
  10387. enum {
  10388. VTIME_SLEEPING = 0,
  10389. @@ -1450,6 +1505,9 @@
  10390. struct task_cputime cputime_expires;
  10391. struct list_head cpu_timers[3];
  10392. +#ifdef CONFIG_PREEMPT_RT_BASE
  10393. + struct task_struct *posix_timer_list;
  10394. +#endif
  10395. /* process credentials */
  10396. const struct cred __rcu *real_cred; /* objective and real subjective task
  10397. @@ -1482,10 +1540,15 @@
  10398. /* signal handlers */
  10399. struct signal_struct *signal;
  10400. struct sighand_struct *sighand;
  10401. + struct sigqueue *sigqueue_cache;
  10402. sigset_t blocked, real_blocked;
  10403. sigset_t saved_sigmask; /* restored if set_restore_sigmask() was used */
  10404. struct sigpending pending;
  10405. +#ifdef CONFIG_PREEMPT_RT_FULL
  10406. + /* TODO: move me into ->restart_block ? */
  10407. + struct siginfo forced_info;
  10408. +#endif
  10409. unsigned long sas_ss_sp;
  10410. size_t sas_ss_size;
  10411. @@ -1511,6 +1574,8 @@
  10412. /* Protection of the PI data structures: */
  10413. raw_spinlock_t pi_lock;
  10414. + struct wake_q_node wake_q;
  10415. +
  10416. #ifdef CONFIG_RT_MUTEXES
  10417. /* PI waiters blocked on a rt_mutex held by this task */
  10418. struct rb_root pi_waiters;
  10419. @@ -1705,6 +1770,12 @@
  10420. unsigned long trace;
  10421. /* bitmask and counter of trace recursion */
  10422. unsigned long trace_recursion;
  10423. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  10424. + u64 preempt_timestamp_hist;
  10425. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  10426. + long timer_offset;
  10427. +#endif
  10428. +#endif
  10429. #endif /* CONFIG_TRACING */
  10430. #ifdef CONFIG_MEMCG
  10431. struct memcg_oom_info {
  10432. @@ -1721,14 +1792,23 @@
  10433. unsigned int sequential_io;
  10434. unsigned int sequential_io_avg;
  10435. #endif
  10436. +#ifdef CONFIG_PREEMPT_RT_BASE
  10437. + struct rcu_head put_rcu;
  10438. + int softirq_nestcnt;
  10439. + unsigned int softirqs_raised;
  10440. +#endif
  10441. +#ifdef CONFIG_PREEMPT_RT_FULL
  10442. +# if defined CONFIG_HIGHMEM || defined CONFIG_X86_32
  10443. + int kmap_idx;
  10444. + pte_t kmap_pte[KM_TYPE_NR];
  10445. +# endif
  10446. +#endif
  10447. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  10448. unsigned long task_state_change;
  10449. #endif
  10450. + int pagefault_disabled;
  10451. };
  10452. -/* Future-safe accessor for struct task_struct's cpus_allowed. */
  10453. -#define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
  10454. -
  10455. #define TNF_MIGRATED 0x01
  10456. #define TNF_NO_GROUP 0x02
  10457. #define TNF_SHARED 0x04
  10458. @@ -1917,6 +1997,15 @@
  10459. extern void free_task(struct task_struct *tsk);
  10460. #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
  10461. +#ifdef CONFIG_PREEMPT_RT_BASE
  10462. +extern void __put_task_struct_cb(struct rcu_head *rhp);
  10463. +
  10464. +static inline void put_task_struct(struct task_struct *t)
  10465. +{
  10466. + if (atomic_dec_and_test(&t->usage))
  10467. + call_rcu(&t->put_rcu, __put_task_struct_cb);
  10468. +}
  10469. +#else
  10470. extern void __put_task_struct(struct task_struct *t);
  10471. static inline void put_task_struct(struct task_struct *t)
  10472. @@ -1924,6 +2013,7 @@
  10473. if (atomic_dec_and_test(&t->usage))
  10474. __put_task_struct(t);
  10475. }
  10476. +#endif
  10477. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  10478. extern void task_cputime(struct task_struct *t,
  10479. @@ -1962,6 +2052,7 @@
  10480. /*
  10481. * Per process flags
  10482. */
  10483. +#define PF_IN_SOFTIRQ 0x00000001 /* Task is serving softirq */
  10484. #define PF_EXITING 0x00000004 /* getting shut down */
  10485. #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */
  10486. #define PF_VCPU 0x00000010 /* I'm a virtual CPU */
  10487. @@ -2126,6 +2217,10 @@
  10488. extern int set_cpus_allowed_ptr(struct task_struct *p,
  10489. const struct cpumask *new_mask);
  10490. +int migrate_me(void);
  10491. +void tell_sched_cpu_down_begin(int cpu);
  10492. +void tell_sched_cpu_down_done(int cpu);
  10493. +
  10494. #else
  10495. static inline void do_set_cpus_allowed(struct task_struct *p,
  10496. const struct cpumask *new_mask)
  10497. @@ -2138,6 +2233,9 @@
  10498. return -EINVAL;
  10499. return 0;
  10500. }
  10501. +static inline int migrate_me(void) { return 0; }
  10502. +static inline void tell_sched_cpu_down_begin(int cpu) { }
  10503. +static inline void tell_sched_cpu_down_done(int cpu) { }
  10504. #endif
  10505. #ifdef CONFIG_NO_HZ_COMMON
  10506. @@ -2354,6 +2452,7 @@
  10507. extern int wake_up_state(struct task_struct *tsk, unsigned int state);
  10508. extern int wake_up_process(struct task_struct *tsk);
  10509. +extern int wake_up_lock_sleeper(struct task_struct * tsk);
  10510. extern void wake_up_new_task(struct task_struct *tsk);
  10511. #ifdef CONFIG_SMP
  10512. extern void kick_process(struct task_struct *tsk);
  10513. @@ -2470,12 +2569,24 @@
  10514. /* mmdrop drops the mm and the page tables */
  10515. extern void __mmdrop(struct mm_struct *);
  10516. +
  10517. static inline void mmdrop(struct mm_struct * mm)
  10518. {
  10519. if (unlikely(atomic_dec_and_test(&mm->mm_count)))
  10520. __mmdrop(mm);
  10521. }
  10522. +#ifdef CONFIG_PREEMPT_RT_BASE
  10523. +extern void __mmdrop_delayed(struct rcu_head *rhp);
  10524. +static inline void mmdrop_delayed(struct mm_struct *mm)
  10525. +{
  10526. + if (atomic_dec_and_test(&mm->mm_count))
  10527. + call_rcu(&mm->delayed_drop, __mmdrop_delayed);
  10528. +}
  10529. +#else
  10530. +# define mmdrop_delayed(mm) mmdrop(mm)
  10531. +#endif
  10532. +
  10533. /* mmput gets rid of the mappings and all user-space */
  10534. extern void mmput(struct mm_struct *);
  10535. /* Grab a reference to a task's mm, if it is not already going away */
  10536. @@ -2787,6 +2898,43 @@
  10537. return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED));
  10538. }
  10539. +#ifdef CONFIG_PREEMPT_LAZY
  10540. +static inline void set_tsk_need_resched_lazy(struct task_struct *tsk)
  10541. +{
  10542. + set_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  10543. +}
  10544. +
  10545. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk)
  10546. +{
  10547. + clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY);
  10548. +}
  10549. +
  10550. +static inline int test_tsk_need_resched_lazy(struct task_struct *tsk)
  10551. +{
  10552. + return unlikely(test_tsk_thread_flag(tsk,TIF_NEED_RESCHED_LAZY));
  10553. +}
  10554. +
  10555. +static inline int need_resched_lazy(void)
  10556. +{
  10557. + return test_thread_flag(TIF_NEED_RESCHED_LAZY);
  10558. +}
  10559. +
  10560. +static inline int need_resched_now(void)
  10561. +{
  10562. + return test_thread_flag(TIF_NEED_RESCHED);
  10563. +}
  10564. +
  10565. +#else
  10566. +static inline void clear_tsk_need_resched_lazy(struct task_struct *tsk) { }
  10567. +static inline int need_resched_lazy(void) { return 0; }
  10568. +
  10569. +static inline int need_resched_now(void)
  10570. +{
  10571. + return test_thread_flag(TIF_NEED_RESCHED);
  10572. +}
  10573. +
  10574. +#endif
  10575. +
  10576. static inline int restart_syscall(void)
  10577. {
  10578. set_tsk_thread_flag(current, TIF_SIGPENDING);
  10579. @@ -2818,6 +2966,51 @@
  10580. return (state & TASK_INTERRUPTIBLE) || __fatal_signal_pending(p);
  10581. }
  10582. +static inline bool __task_is_stopped_or_traced(struct task_struct *task)
  10583. +{
  10584. + if (task->state & (__TASK_STOPPED | __TASK_TRACED))
  10585. + return true;
  10586. +#ifdef CONFIG_PREEMPT_RT_FULL
  10587. + if (task->saved_state & (__TASK_STOPPED | __TASK_TRACED))
  10588. + return true;
  10589. +#endif
  10590. + return false;
  10591. +}
  10592. +
  10593. +static inline bool task_is_stopped_or_traced(struct task_struct *task)
  10594. +{
  10595. + bool traced_stopped;
  10596. +
  10597. +#ifdef CONFIG_PREEMPT_RT_FULL
  10598. + unsigned long flags;
  10599. +
  10600. + raw_spin_lock_irqsave(&task->pi_lock, flags);
  10601. + traced_stopped = __task_is_stopped_or_traced(task);
  10602. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  10603. +#else
  10604. + traced_stopped = __task_is_stopped_or_traced(task);
  10605. +#endif
  10606. + return traced_stopped;
  10607. +}
  10608. +
  10609. +static inline bool task_is_traced(struct task_struct *task)
  10610. +{
  10611. + bool traced = false;
  10612. +
  10613. + if (task->state & __TASK_TRACED)
  10614. + return true;
  10615. +#ifdef CONFIG_PREEMPT_RT_FULL
  10616. + /* in case the task is sleeping on tasklist_lock */
  10617. + raw_spin_lock_irq(&task->pi_lock);
  10618. + if (task->state & __TASK_TRACED)
  10619. + traced = true;
  10620. + else if (task->saved_state & __TASK_TRACED)
  10621. + traced = true;
  10622. + raw_spin_unlock_irq(&task->pi_lock);
  10623. +#endif
  10624. + return traced;
  10625. +}
  10626. +
  10627. /*
  10628. * cond_resched() and cond_resched_lock(): latency reduction via
  10629. * explicit rescheduling in places that are safe. The return
  10630. @@ -2834,7 +3027,7 @@
  10631. extern int __cond_resched_lock(spinlock_t *lock);
  10632. -#ifdef CONFIG_PREEMPT_COUNT
  10633. +#if defined(CONFIG_PREEMPT_COUNT) && !defined(CONFIG_PREEMPT_RT_FULL)
  10634. #define PREEMPT_LOCK_OFFSET PREEMPT_OFFSET
  10635. #else
  10636. #define PREEMPT_LOCK_OFFSET 0
  10637. @@ -2845,12 +3038,16 @@
  10638. __cond_resched_lock(lock); \
  10639. })
  10640. +#ifndef CONFIG_PREEMPT_RT_FULL
  10641. extern int __cond_resched_softirq(void);
  10642. #define cond_resched_softirq() ({ \
  10643. ___might_sleep(__FILE__, __LINE__, SOFTIRQ_DISABLE_OFFSET); \
  10644. __cond_resched_softirq(); \
  10645. })
  10646. +#else
  10647. +# define cond_resched_softirq() cond_resched()
  10648. +#endif
  10649. static inline void cond_resched_rcu(void)
  10650. {
  10651. @@ -3017,6 +3214,26 @@
  10652. #endif /* CONFIG_SMP */
  10653. +static inline int __migrate_disabled(struct task_struct *p)
  10654. +{
  10655. +#ifdef CONFIG_PREEMPT_RT_FULL
  10656. + return p->migrate_disable;
  10657. +#else
  10658. + return 0;
  10659. +#endif
  10660. +}
  10661. +
  10662. +/* Future-safe accessor for struct task_struct's cpus_allowed. */
  10663. +static inline const struct cpumask *tsk_cpus_allowed(struct task_struct *p)
  10664. +{
  10665. +#ifdef CONFIG_PREEMPT_RT_FULL
  10666. + if (p->migrate_disable)
  10667. + return cpumask_of(task_cpu(p));
  10668. +#endif
  10669. +
  10670. + return &p->cpus_allowed;
  10671. +}
  10672. +
  10673. extern long sched_setaffinity(pid_t pid, const struct cpumask *new_mask);
  10674. extern long sched_getaffinity(pid_t pid, struct cpumask *mask);
  10675. diff -Nur linux-4.1.6.orig/include/linux/seqlock.h linux-4.1.6/include/linux/seqlock.h
  10676. --- linux-4.1.6.orig/include/linux/seqlock.h 2015-08-17 05:52:51.000000000 +0200
  10677. +++ linux-4.1.6/include/linux/seqlock.h 2015-09-08 23:49:06.778014632 +0200
  10678. @@ -219,20 +219,30 @@
  10679. return __read_seqcount_retry(s, start);
  10680. }
  10681. -
  10682. -
  10683. -static inline void raw_write_seqcount_begin(seqcount_t *s)
  10684. +static inline void __raw_write_seqcount_begin(seqcount_t *s)
  10685. {
  10686. s->sequence++;
  10687. smp_wmb();
  10688. }
  10689. -static inline void raw_write_seqcount_end(seqcount_t *s)
  10690. +static inline void raw_write_seqcount_begin(seqcount_t *s)
  10691. +{
  10692. + preempt_disable_rt();
  10693. + __raw_write_seqcount_begin(s);
  10694. +}
  10695. +
  10696. +static inline void __raw_write_seqcount_end(seqcount_t *s)
  10697. {
  10698. smp_wmb();
  10699. s->sequence++;
  10700. }
  10701. +static inline void raw_write_seqcount_end(seqcount_t *s)
  10702. +{
  10703. + __raw_write_seqcount_end(s);
  10704. + preempt_enable_rt();
  10705. +}
  10706. +
  10707. /*
  10708. * raw_write_seqcount_latch - redirect readers to even/odd copy
  10709. * @s: pointer to seqcount_t
  10710. @@ -305,10 +315,32 @@
  10711. /*
  10712. * Read side functions for starting and finalizing a read side section.
  10713. */
  10714. +#ifndef CONFIG_PREEMPT_RT_FULL
  10715. static inline unsigned read_seqbegin(const seqlock_t *sl)
  10716. {
  10717. return read_seqcount_begin(&sl->seqcount);
  10718. }
  10719. +#else
  10720. +/*
  10721. + * Starvation safe read side for RT
  10722. + */
  10723. +static inline unsigned read_seqbegin(seqlock_t *sl)
  10724. +{
  10725. + unsigned ret;
  10726. +
  10727. +repeat:
  10728. + ret = ACCESS_ONCE(sl->seqcount.sequence);
  10729. + if (unlikely(ret & 1)) {
  10730. + /*
  10731. + * Take the lock and let the writer proceed (i.e. evtl
  10732. + * boost it), otherwise we could loop here forever.
  10733. + */
  10734. + spin_unlock_wait(&sl->lock);
  10735. + goto repeat;
  10736. + }
  10737. + return ret;
  10738. +}
  10739. +#endif
  10740. static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
  10741. {
  10742. @@ -323,36 +355,36 @@
  10743. static inline void write_seqlock(seqlock_t *sl)
  10744. {
  10745. spin_lock(&sl->lock);
  10746. - write_seqcount_begin(&sl->seqcount);
  10747. + __raw_write_seqcount_begin(&sl->seqcount);
  10748. }
  10749. static inline void write_sequnlock(seqlock_t *sl)
  10750. {
  10751. - write_seqcount_end(&sl->seqcount);
  10752. + __raw_write_seqcount_end(&sl->seqcount);
  10753. spin_unlock(&sl->lock);
  10754. }
  10755. static inline void write_seqlock_bh(seqlock_t *sl)
  10756. {
  10757. spin_lock_bh(&sl->lock);
  10758. - write_seqcount_begin(&sl->seqcount);
  10759. + __raw_write_seqcount_begin(&sl->seqcount);
  10760. }
  10761. static inline void write_sequnlock_bh(seqlock_t *sl)
  10762. {
  10763. - write_seqcount_end(&sl->seqcount);
  10764. + __raw_write_seqcount_end(&sl->seqcount);
  10765. spin_unlock_bh(&sl->lock);
  10766. }
  10767. static inline void write_seqlock_irq(seqlock_t *sl)
  10768. {
  10769. spin_lock_irq(&sl->lock);
  10770. - write_seqcount_begin(&sl->seqcount);
  10771. + __raw_write_seqcount_begin(&sl->seqcount);
  10772. }
  10773. static inline void write_sequnlock_irq(seqlock_t *sl)
  10774. {
  10775. - write_seqcount_end(&sl->seqcount);
  10776. + __raw_write_seqcount_end(&sl->seqcount);
  10777. spin_unlock_irq(&sl->lock);
  10778. }
  10779. @@ -361,7 +393,7 @@
  10780. unsigned long flags;
  10781. spin_lock_irqsave(&sl->lock, flags);
  10782. - write_seqcount_begin(&sl->seqcount);
  10783. + __raw_write_seqcount_begin(&sl->seqcount);
  10784. return flags;
  10785. }
  10786. @@ -371,7 +403,7 @@
  10787. static inline void
  10788. write_sequnlock_irqrestore(seqlock_t *sl, unsigned long flags)
  10789. {
  10790. - write_seqcount_end(&sl->seqcount);
  10791. + __raw_write_seqcount_end(&sl->seqcount);
  10792. spin_unlock_irqrestore(&sl->lock, flags);
  10793. }
  10794. diff -Nur linux-4.1.6.orig/include/linux/signal.h linux-4.1.6/include/linux/signal.h
  10795. --- linux-4.1.6.orig/include/linux/signal.h 2015-08-17 05:52:51.000000000 +0200
  10796. +++ linux-4.1.6/include/linux/signal.h 2015-09-08 23:49:06.778014632 +0200
  10797. @@ -218,6 +218,7 @@
  10798. }
  10799. extern void flush_sigqueue(struct sigpending *queue);
  10800. +extern void flush_task_sigqueue(struct task_struct *tsk);
  10801. /* Test if 'sig' is valid signal. Use this instead of testing _NSIG directly */
  10802. static inline int valid_signal(unsigned long sig)
  10803. diff -Nur linux-4.1.6.orig/include/linux/skbuff.h linux-4.1.6/include/linux/skbuff.h
  10804. --- linux-4.1.6.orig/include/linux/skbuff.h 2015-08-17 05:52:51.000000000 +0200
  10805. +++ linux-4.1.6/include/linux/skbuff.h 2015-09-08 23:49:06.782014188 +0200
  10806. @@ -187,6 +187,7 @@
  10807. __u32 qlen;
  10808. spinlock_t lock;
  10809. + raw_spinlock_t raw_lock;
  10810. };
  10811. struct sk_buff;
  10812. @@ -1336,6 +1337,12 @@
  10813. __skb_queue_head_init(list);
  10814. }
  10815. +static inline void skb_queue_head_init_raw(struct sk_buff_head *list)
  10816. +{
  10817. + raw_spin_lock_init(&list->raw_lock);
  10818. + __skb_queue_head_init(list);
  10819. +}
  10820. +
  10821. static inline void skb_queue_head_init_class(struct sk_buff_head *list,
  10822. struct lock_class_key *class)
  10823. {
  10824. diff -Nur linux-4.1.6.orig/include/linux/smp.h linux-4.1.6/include/linux/smp.h
  10825. --- linux-4.1.6.orig/include/linux/smp.h 2015-08-17 05:52:51.000000000 +0200
  10826. +++ linux-4.1.6/include/linux/smp.h 2015-09-08 23:49:06.782014188 +0200
  10827. @@ -185,6 +185,9 @@
  10828. #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
  10829. #define put_cpu() preempt_enable()
  10830. +#define get_cpu_light() ({ migrate_disable(); smp_processor_id(); })
  10831. +#define put_cpu_light() migrate_enable()
  10832. +
  10833. /*
  10834. * Callback to arch code if there's nosmp or maxcpus=0 on the
  10835. * boot command line:
  10836. diff -Nur linux-4.1.6.orig/include/linux/spinlock_api_smp.h linux-4.1.6/include/linux/spinlock_api_smp.h
  10837. --- linux-4.1.6.orig/include/linux/spinlock_api_smp.h 2015-08-17 05:52:51.000000000 +0200
  10838. +++ linux-4.1.6/include/linux/spinlock_api_smp.h 2015-09-08 23:49:06.782014188 +0200
  10839. @@ -189,6 +189,8 @@
  10840. return 0;
  10841. }
  10842. -#include <linux/rwlock_api_smp.h>
  10843. +#ifndef CONFIG_PREEMPT_RT_FULL
  10844. +# include <linux/rwlock_api_smp.h>
  10845. +#endif
  10846. #endif /* __LINUX_SPINLOCK_API_SMP_H */
  10847. diff -Nur linux-4.1.6.orig/include/linux/spinlock.h linux-4.1.6/include/linux/spinlock.h
  10848. --- linux-4.1.6.orig/include/linux/spinlock.h 2015-08-17 05:52:51.000000000 +0200
  10849. +++ linux-4.1.6/include/linux/spinlock.h 2015-09-08 23:49:06.782014188 +0200
  10850. @@ -281,7 +281,11 @@
  10851. #define raw_spin_can_lock(lock) (!raw_spin_is_locked(lock))
  10852. /* Include rwlock functions */
  10853. -#include <linux/rwlock.h>
  10854. +#ifdef CONFIG_PREEMPT_RT_FULL
  10855. +# include <linux/rwlock_rt.h>
  10856. +#else
  10857. +# include <linux/rwlock.h>
  10858. +#endif
  10859. /*
  10860. * Pull the _spin_*()/_read_*()/_write_*() functions/declarations:
  10861. @@ -292,6 +296,10 @@
  10862. # include <linux/spinlock_api_up.h>
  10863. #endif
  10864. +#ifdef CONFIG_PREEMPT_RT_FULL
  10865. +# include <linux/spinlock_rt.h>
  10866. +#else /* PREEMPT_RT_FULL */
  10867. +
  10868. /*
  10869. * Map the spin_lock functions to the raw variants for PREEMPT_RT=n
  10870. */
  10871. @@ -426,4 +434,6 @@
  10872. #define atomic_dec_and_lock(atomic, lock) \
  10873. __cond_lock(lock, _atomic_dec_and_lock(atomic, lock))
  10874. +#endif /* !PREEMPT_RT_FULL */
  10875. +
  10876. #endif /* __LINUX_SPINLOCK_H */
  10877. diff -Nur linux-4.1.6.orig/include/linux/spinlock_rt.h linux-4.1.6/include/linux/spinlock_rt.h
  10878. --- linux-4.1.6.orig/include/linux/spinlock_rt.h 1970-01-01 01:00:00.000000000 +0100
  10879. +++ linux-4.1.6/include/linux/spinlock_rt.h 2015-09-08 23:49:06.782014188 +0200
  10880. @@ -0,0 +1,174 @@
  10881. +#ifndef __LINUX_SPINLOCK_RT_H
  10882. +#define __LINUX_SPINLOCK_RT_H
  10883. +
  10884. +#ifndef __LINUX_SPINLOCK_H
  10885. +#error Do not include directly. Use spinlock.h
  10886. +#endif
  10887. +
  10888. +#include <linux/bug.h>
  10889. +
  10890. +extern void
  10891. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key);
  10892. +
  10893. +#define spin_lock_init(slock) \
  10894. +do { \
  10895. + static struct lock_class_key __key; \
  10896. + \
  10897. + rt_mutex_init(&(slock)->lock); \
  10898. + __rt_spin_lock_init(slock, #slock, &__key); \
  10899. +} while (0)
  10900. +
  10901. +extern void __lockfunc rt_spin_lock(spinlock_t *lock);
  10902. +extern unsigned long __lockfunc rt_spin_lock_trace_flags(spinlock_t *lock);
  10903. +extern void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass);
  10904. +extern void __lockfunc rt_spin_unlock(spinlock_t *lock);
  10905. +extern void __lockfunc rt_spin_unlock_wait(spinlock_t *lock);
  10906. +extern int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags);
  10907. +extern int __lockfunc rt_spin_trylock_bh(spinlock_t *lock);
  10908. +extern int __lockfunc rt_spin_trylock(spinlock_t *lock);
  10909. +extern int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock);
  10910. +
  10911. +/*
  10912. + * lockdep-less calls, for derived types like rwlock:
  10913. + * (for trylock they can use rt_mutex_trylock() directly.
  10914. + */
  10915. +extern void __lockfunc __rt_spin_lock(struct rt_mutex *lock);
  10916. +extern void __lockfunc __rt_spin_unlock(struct rt_mutex *lock);
  10917. +extern int __lockfunc __rt_spin_trylock(struct rt_mutex *lock);
  10918. +
  10919. +#define spin_lock(lock) \
  10920. + do { \
  10921. + migrate_disable(); \
  10922. + rt_spin_lock(lock); \
  10923. + } while (0)
  10924. +
  10925. +#define spin_lock_bh(lock) \
  10926. + do { \
  10927. + local_bh_disable(); \
  10928. + migrate_disable(); \
  10929. + rt_spin_lock(lock); \
  10930. + } while (0)
  10931. +
  10932. +#define spin_lock_irq(lock) spin_lock(lock)
  10933. +
  10934. +#define spin_do_trylock(lock) __cond_lock(lock, rt_spin_trylock(lock))
  10935. +
  10936. +#define spin_trylock(lock) \
  10937. +({ \
  10938. + int __locked; \
  10939. + migrate_disable(); \
  10940. + __locked = spin_do_trylock(lock); \
  10941. + if (!__locked) \
  10942. + migrate_enable(); \
  10943. + __locked; \
  10944. +})
  10945. +
  10946. +#ifdef CONFIG_LOCKDEP
  10947. +# define spin_lock_nested(lock, subclass) \
  10948. + do { \
  10949. + migrate_disable(); \
  10950. + rt_spin_lock_nested(lock, subclass); \
  10951. + } while (0)
  10952. +
  10953. +#define spin_lock_bh_nested(lock, subclass) \
  10954. + do { \
  10955. + local_bh_disable(); \
  10956. + migrate_disable(); \
  10957. + rt_spin_lock_nested(lock, subclass); \
  10958. + } while (0)
  10959. +
  10960. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  10961. + do { \
  10962. + typecheck(unsigned long, flags); \
  10963. + flags = 0; \
  10964. + migrate_disable(); \
  10965. + rt_spin_lock_nested(lock, subclass); \
  10966. + } while (0)
  10967. +#else
  10968. +# define spin_lock_nested(lock, subclass) spin_lock(lock)
  10969. +# define spin_lock_bh_nested(lock, subclass) spin_lock_bh(lock)
  10970. +
  10971. +# define spin_lock_irqsave_nested(lock, flags, subclass) \
  10972. + do { \
  10973. + typecheck(unsigned long, flags); \
  10974. + flags = 0; \
  10975. + spin_lock(lock); \
  10976. + } while (0)
  10977. +#endif
  10978. +
  10979. +#define spin_lock_irqsave(lock, flags) \
  10980. + do { \
  10981. + typecheck(unsigned long, flags); \
  10982. + flags = 0; \
  10983. + spin_lock(lock); \
  10984. + } while (0)
  10985. +
  10986. +static inline unsigned long spin_lock_trace_flags(spinlock_t *lock)
  10987. +{
  10988. + unsigned long flags = 0;
  10989. +#ifdef CONFIG_TRACE_IRQFLAGS
  10990. + flags = rt_spin_lock_trace_flags(lock);
  10991. +#else
  10992. + spin_lock(lock); /* lock_local */
  10993. +#endif
  10994. + return flags;
  10995. +}
  10996. +
  10997. +/* FIXME: we need rt_spin_lock_nest_lock */
  10998. +#define spin_lock_nest_lock(lock, nest_lock) spin_lock_nested(lock, 0)
  10999. +
  11000. +#define spin_unlock(lock) \
  11001. + do { \
  11002. + rt_spin_unlock(lock); \
  11003. + migrate_enable(); \
  11004. + } while (0)
  11005. +
  11006. +#define spin_unlock_bh(lock) \
  11007. + do { \
  11008. + rt_spin_unlock(lock); \
  11009. + migrate_enable(); \
  11010. + local_bh_enable(); \
  11011. + } while (0)
  11012. +
  11013. +#define spin_unlock_irq(lock) spin_unlock(lock)
  11014. +
  11015. +#define spin_unlock_irqrestore(lock, flags) \
  11016. + do { \
  11017. + typecheck(unsigned long, flags); \
  11018. + (void) flags; \
  11019. + spin_unlock(lock); \
  11020. + } while (0)
  11021. +
  11022. +#define spin_trylock_bh(lock) __cond_lock(lock, rt_spin_trylock_bh(lock))
  11023. +#define spin_trylock_irq(lock) spin_trylock(lock)
  11024. +
  11025. +#define spin_trylock_irqsave(lock, flags) \
  11026. + rt_spin_trylock_irqsave(lock, &(flags))
  11027. +
  11028. +#define spin_unlock_wait(lock) rt_spin_unlock_wait(lock)
  11029. +
  11030. +#ifdef CONFIG_GENERIC_LOCKBREAK
  11031. +# define spin_is_contended(lock) ((lock)->break_lock)
  11032. +#else
  11033. +# define spin_is_contended(lock) (((void)(lock), 0))
  11034. +#endif
  11035. +
  11036. +static inline int spin_can_lock(spinlock_t *lock)
  11037. +{
  11038. + return !rt_mutex_is_locked(&lock->lock);
  11039. +}
  11040. +
  11041. +static inline int spin_is_locked(spinlock_t *lock)
  11042. +{
  11043. + return rt_mutex_is_locked(&lock->lock);
  11044. +}
  11045. +
  11046. +static inline void assert_spin_locked(spinlock_t *lock)
  11047. +{
  11048. + BUG_ON(!spin_is_locked(lock));
  11049. +}
  11050. +
  11051. +#define atomic_dec_and_lock(atomic, lock) \
  11052. + atomic_dec_and_spin_lock(atomic, lock)
  11053. +
  11054. +#endif
  11055. diff -Nur linux-4.1.6.orig/include/linux/spinlock_types.h linux-4.1.6/include/linux/spinlock_types.h
  11056. --- linux-4.1.6.orig/include/linux/spinlock_types.h 2015-08-17 05:52:51.000000000 +0200
  11057. +++ linux-4.1.6/include/linux/spinlock_types.h 2015-09-08 23:49:06.782014188 +0200
  11058. @@ -9,80 +9,15 @@
  11059. * Released under the General Public License (GPL).
  11060. */
  11061. -#if defined(CONFIG_SMP)
  11062. -# include <asm/spinlock_types.h>
  11063. -#else
  11064. -# include <linux/spinlock_types_up.h>
  11065. -#endif
  11066. -
  11067. -#include <linux/lockdep.h>
  11068. -
  11069. -typedef struct raw_spinlock {
  11070. - arch_spinlock_t raw_lock;
  11071. -#ifdef CONFIG_GENERIC_LOCKBREAK
  11072. - unsigned int break_lock;
  11073. -#endif
  11074. -#ifdef CONFIG_DEBUG_SPINLOCK
  11075. - unsigned int magic, owner_cpu;
  11076. - void *owner;
  11077. -#endif
  11078. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11079. - struct lockdep_map dep_map;
  11080. -#endif
  11081. -} raw_spinlock_t;
  11082. -
  11083. -#define SPINLOCK_MAGIC 0xdead4ead
  11084. -
  11085. -#define SPINLOCK_OWNER_INIT ((void *)-1L)
  11086. -
  11087. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11088. -# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  11089. -#else
  11090. -# define SPIN_DEP_MAP_INIT(lockname)
  11091. -#endif
  11092. +#include <linux/spinlock_types_raw.h>
  11093. -#ifdef CONFIG_DEBUG_SPINLOCK
  11094. -# define SPIN_DEBUG_INIT(lockname) \
  11095. - .magic = SPINLOCK_MAGIC, \
  11096. - .owner_cpu = -1, \
  11097. - .owner = SPINLOCK_OWNER_INIT,
  11098. +#ifndef CONFIG_PREEMPT_RT_FULL
  11099. +# include <linux/spinlock_types_nort.h>
  11100. +# include <linux/rwlock_types.h>
  11101. #else
  11102. -# define SPIN_DEBUG_INIT(lockname)
  11103. +# include <linux/rtmutex.h>
  11104. +# include <linux/spinlock_types_rt.h>
  11105. +# include <linux/rwlock_types_rt.h>
  11106. #endif
  11107. -#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  11108. - { \
  11109. - .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  11110. - SPIN_DEBUG_INIT(lockname) \
  11111. - SPIN_DEP_MAP_INIT(lockname) }
  11112. -
  11113. -#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  11114. - (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  11115. -
  11116. -#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  11117. -
  11118. -typedef struct spinlock {
  11119. - union {
  11120. - struct raw_spinlock rlock;
  11121. -
  11122. -#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11123. -# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  11124. - struct {
  11125. - u8 __padding[LOCK_PADSIZE];
  11126. - struct lockdep_map dep_map;
  11127. - };
  11128. -#endif
  11129. - };
  11130. -} spinlock_t;
  11131. -
  11132. -#define __SPIN_LOCK_INITIALIZER(lockname) \
  11133. - { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  11134. -
  11135. -#define __SPIN_LOCK_UNLOCKED(lockname) \
  11136. - (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  11137. -
  11138. -#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  11139. -
  11140. -#include <linux/rwlock_types.h>
  11141. -
  11142. #endif /* __LINUX_SPINLOCK_TYPES_H */
  11143. diff -Nur linux-4.1.6.orig/include/linux/spinlock_types_nort.h linux-4.1.6/include/linux/spinlock_types_nort.h
  11144. --- linux-4.1.6.orig/include/linux/spinlock_types_nort.h 1970-01-01 01:00:00.000000000 +0100
  11145. +++ linux-4.1.6/include/linux/spinlock_types_nort.h 2015-09-08 23:49:06.782014188 +0200
  11146. @@ -0,0 +1,33 @@
  11147. +#ifndef __LINUX_SPINLOCK_TYPES_NORT_H
  11148. +#define __LINUX_SPINLOCK_TYPES_NORT_H
  11149. +
  11150. +#ifndef __LINUX_SPINLOCK_TYPES_H
  11151. +#error "Do not include directly. Include spinlock_types.h instead"
  11152. +#endif
  11153. +
  11154. +/*
  11155. + * The non RT version maps spinlocks to raw_spinlocks
  11156. + */
  11157. +typedef struct spinlock {
  11158. + union {
  11159. + struct raw_spinlock rlock;
  11160. +
  11161. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11162. +# define LOCK_PADSIZE (offsetof(struct raw_spinlock, dep_map))
  11163. + struct {
  11164. + u8 __padding[LOCK_PADSIZE];
  11165. + struct lockdep_map dep_map;
  11166. + };
  11167. +#endif
  11168. + };
  11169. +} spinlock_t;
  11170. +
  11171. +#define __SPIN_LOCK_INITIALIZER(lockname) \
  11172. + { { .rlock = __RAW_SPIN_LOCK_INITIALIZER(lockname) } }
  11173. +
  11174. +#define __SPIN_LOCK_UNLOCKED(lockname) \
  11175. + (spinlock_t ) __SPIN_LOCK_INITIALIZER(lockname)
  11176. +
  11177. +#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
  11178. +
  11179. +#endif
  11180. diff -Nur linux-4.1.6.orig/include/linux/spinlock_types_raw.h linux-4.1.6/include/linux/spinlock_types_raw.h
  11181. --- linux-4.1.6.orig/include/linux/spinlock_types_raw.h 1970-01-01 01:00:00.000000000 +0100
  11182. +++ linux-4.1.6/include/linux/spinlock_types_raw.h 2015-09-08 23:49:06.782014188 +0200
  11183. @@ -0,0 +1,56 @@
  11184. +#ifndef __LINUX_SPINLOCK_TYPES_RAW_H
  11185. +#define __LINUX_SPINLOCK_TYPES_RAW_H
  11186. +
  11187. +#if defined(CONFIG_SMP)
  11188. +# include <asm/spinlock_types.h>
  11189. +#else
  11190. +# include <linux/spinlock_types_up.h>
  11191. +#endif
  11192. +
  11193. +#include <linux/lockdep.h>
  11194. +
  11195. +typedef struct raw_spinlock {
  11196. + arch_spinlock_t raw_lock;
  11197. +#ifdef CONFIG_GENERIC_LOCKBREAK
  11198. + unsigned int break_lock;
  11199. +#endif
  11200. +#ifdef CONFIG_DEBUG_SPINLOCK
  11201. + unsigned int magic, owner_cpu;
  11202. + void *owner;
  11203. +#endif
  11204. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11205. + struct lockdep_map dep_map;
  11206. +#endif
  11207. +} raw_spinlock_t;
  11208. +
  11209. +#define SPINLOCK_MAGIC 0xdead4ead
  11210. +
  11211. +#define SPINLOCK_OWNER_INIT ((void *)-1L)
  11212. +
  11213. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11214. +# define SPIN_DEP_MAP_INIT(lockname) .dep_map = { .name = #lockname }
  11215. +#else
  11216. +# define SPIN_DEP_MAP_INIT(lockname)
  11217. +#endif
  11218. +
  11219. +#ifdef CONFIG_DEBUG_SPINLOCK
  11220. +# define SPIN_DEBUG_INIT(lockname) \
  11221. + .magic = SPINLOCK_MAGIC, \
  11222. + .owner_cpu = -1, \
  11223. + .owner = SPINLOCK_OWNER_INIT,
  11224. +#else
  11225. +# define SPIN_DEBUG_INIT(lockname)
  11226. +#endif
  11227. +
  11228. +#define __RAW_SPIN_LOCK_INITIALIZER(lockname) \
  11229. + { \
  11230. + .raw_lock = __ARCH_SPIN_LOCK_UNLOCKED, \
  11231. + SPIN_DEBUG_INIT(lockname) \
  11232. + SPIN_DEP_MAP_INIT(lockname) }
  11233. +
  11234. +#define __RAW_SPIN_LOCK_UNLOCKED(lockname) \
  11235. + (raw_spinlock_t) __RAW_SPIN_LOCK_INITIALIZER(lockname)
  11236. +
  11237. +#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x = __RAW_SPIN_LOCK_UNLOCKED(x)
  11238. +
  11239. +#endif
  11240. diff -Nur linux-4.1.6.orig/include/linux/spinlock_types_rt.h linux-4.1.6/include/linux/spinlock_types_rt.h
  11241. --- linux-4.1.6.orig/include/linux/spinlock_types_rt.h 1970-01-01 01:00:00.000000000 +0100
  11242. +++ linux-4.1.6/include/linux/spinlock_types_rt.h 2015-09-08 23:49:06.782014188 +0200
  11243. @@ -0,0 +1,51 @@
  11244. +#ifndef __LINUX_SPINLOCK_TYPES_RT_H
  11245. +#define __LINUX_SPINLOCK_TYPES_RT_H
  11246. +
  11247. +#ifndef __LINUX_SPINLOCK_TYPES_H
  11248. +#error "Do not include directly. Include spinlock_types.h instead"
  11249. +#endif
  11250. +
  11251. +#include <linux/cache.h>
  11252. +
  11253. +/*
  11254. + * PREEMPT_RT: spinlocks - an RT mutex plus lock-break field:
  11255. + */
  11256. +typedef struct spinlock {
  11257. + struct rt_mutex lock;
  11258. + unsigned int break_lock;
  11259. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  11260. + struct lockdep_map dep_map;
  11261. +#endif
  11262. +} spinlock_t;
  11263. +
  11264. +#ifdef CONFIG_DEBUG_RT_MUTEXES
  11265. +# define __RT_SPIN_INITIALIZER(name) \
  11266. + { \
  11267. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  11268. + .save_state = 1, \
  11269. + .file = __FILE__, \
  11270. + .line = __LINE__ , \
  11271. + }
  11272. +#else
  11273. +# define __RT_SPIN_INITIALIZER(name) \
  11274. + { \
  11275. + .wait_lock = __RAW_SPIN_LOCK_UNLOCKED(name.wait_lock), \
  11276. + .save_state = 1, \
  11277. + }
  11278. +#endif
  11279. +
  11280. +/*
  11281. +.wait_list = PLIST_HEAD_INIT_RAW((name).lock.wait_list, (name).lock.wait_lock)
  11282. +*/
  11283. +
  11284. +#define __SPIN_LOCK_UNLOCKED(name) \
  11285. + { .lock = __RT_SPIN_INITIALIZER(name.lock), \
  11286. + SPIN_DEP_MAP_INIT(name) }
  11287. +
  11288. +#define __DEFINE_SPINLOCK(name) \
  11289. + spinlock_t name = __SPIN_LOCK_UNLOCKED(name)
  11290. +
  11291. +#define DEFINE_SPINLOCK(name) \
  11292. + spinlock_t name __cacheline_aligned_in_smp = __SPIN_LOCK_UNLOCKED(name)
  11293. +
  11294. +#endif
  11295. diff -Nur linux-4.1.6.orig/include/linux/srcu.h linux-4.1.6/include/linux/srcu.h
  11296. --- linux-4.1.6.orig/include/linux/srcu.h 2015-08-17 05:52:51.000000000 +0200
  11297. +++ linux-4.1.6/include/linux/srcu.h 2015-09-08 23:49:06.782014188 +0200
  11298. @@ -84,10 +84,10 @@
  11299. void process_srcu(struct work_struct *work);
  11300. -#define __SRCU_STRUCT_INIT(name) \
  11301. +#define __SRCU_STRUCT_INIT(name, pcpu_name) \
  11302. { \
  11303. .completed = -300, \
  11304. - .per_cpu_ref = &name##_srcu_array, \
  11305. + .per_cpu_ref = &pcpu_name, \
  11306. .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
  11307. .running = false, \
  11308. .batch_queue = RCU_BATCH_INIT(name.batch_queue), \
  11309. @@ -104,7 +104,7 @@
  11310. */
  11311. #define __DEFINE_SRCU(name, is_static) \
  11312. static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
  11313. - is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
  11314. + is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_array)
  11315. #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
  11316. #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
  11317. diff -Nur linux-4.1.6.orig/include/linux/swap.h linux-4.1.6/include/linux/swap.h
  11318. --- linux-4.1.6.orig/include/linux/swap.h 2015-08-17 05:52:51.000000000 +0200
  11319. +++ linux-4.1.6/include/linux/swap.h 2015-09-08 23:49:06.782014188 +0200
  11320. @@ -11,6 +11,7 @@
  11321. #include <linux/fs.h>
  11322. #include <linux/atomic.h>
  11323. #include <linux/page-flags.h>
  11324. +#include <linux/locallock.h>
  11325. #include <asm/page.h>
  11326. struct notifier_block;
  11327. @@ -252,7 +253,8 @@
  11328. void *workingset_eviction(struct address_space *mapping, struct page *page);
  11329. bool workingset_refault(void *shadow);
  11330. void workingset_activation(struct page *page);
  11331. -extern struct list_lru workingset_shadow_nodes;
  11332. +extern struct list_lru __workingset_shadow_nodes;
  11333. +DECLARE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  11334. static inline unsigned int workingset_node_pages(struct radix_tree_node *node)
  11335. {
  11336. @@ -296,6 +298,7 @@
  11337. /* linux/mm/swap.c */
  11338. +DECLARE_LOCAL_IRQ_LOCK(swapvec_lock);
  11339. extern void lru_cache_add(struct page *);
  11340. extern void lru_cache_add_anon(struct page *page);
  11341. extern void lru_cache_add_file(struct page *page);
  11342. diff -Nur linux-4.1.6.orig/include/linux/thread_info.h linux-4.1.6/include/linux/thread_info.h
  11343. --- linux-4.1.6.orig/include/linux/thread_info.h 2015-08-17 05:52:51.000000000 +0200
  11344. +++ linux-4.1.6/include/linux/thread_info.h 2015-09-08 23:49:06.782014188 +0200
  11345. @@ -102,7 +102,17 @@
  11346. #define test_thread_flag(flag) \
  11347. test_ti_thread_flag(current_thread_info(), flag)
  11348. -#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  11349. +#ifdef CONFIG_PREEMPT_LAZY
  11350. +#define tif_need_resched() (test_thread_flag(TIF_NEED_RESCHED) || \
  11351. + test_thread_flag(TIF_NEED_RESCHED_LAZY))
  11352. +#define tif_need_resched_now() (test_thread_flag(TIF_NEED_RESCHED))
  11353. +#define tif_need_resched_lazy() test_thread_flag(TIF_NEED_RESCHED_LAZY))
  11354. +
  11355. +#else
  11356. +#define tif_need_resched() test_thread_flag(TIF_NEED_RESCHED)
  11357. +#define tif_need_resched_now() test_thread_flag(TIF_NEED_RESCHED)
  11358. +#define tif_need_resched_lazy() 0
  11359. +#endif
  11360. #if defined TIF_RESTORE_SIGMASK && !defined HAVE_SET_RESTORE_SIGMASK
  11361. /*
  11362. diff -Nur linux-4.1.6.orig/include/linux/timer.h linux-4.1.6/include/linux/timer.h
  11363. --- linux-4.1.6.orig/include/linux/timer.h 2015-08-17 05:52:51.000000000 +0200
  11364. +++ linux-4.1.6/include/linux/timer.h 2015-09-08 23:49:06.782014188 +0200
  11365. @@ -241,7 +241,7 @@
  11366. extern int try_to_del_timer_sync(struct timer_list *timer);
  11367. -#ifdef CONFIG_SMP
  11368. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  11369. extern int del_timer_sync(struct timer_list *timer);
  11370. #else
  11371. # define del_timer_sync(t) del_timer(t)
  11372. diff -Nur linux-4.1.6.orig/include/linux/uaccess.h linux-4.1.6/include/linux/uaccess.h
  11373. --- linux-4.1.6.orig/include/linux/uaccess.h 2015-08-17 05:52:51.000000000 +0200
  11374. +++ linux-4.1.6/include/linux/uaccess.h 2015-09-08 23:49:06.782014188 +0200
  11375. @@ -1,21 +1,31 @@
  11376. #ifndef __LINUX_UACCESS_H__
  11377. #define __LINUX_UACCESS_H__
  11378. -#include <linux/preempt.h>
  11379. +#include <linux/sched.h>
  11380. #include <asm/uaccess.h>
  11381. +static __always_inline void pagefault_disabled_inc(void)
  11382. +{
  11383. + current->pagefault_disabled++;
  11384. +}
  11385. +
  11386. +static __always_inline void pagefault_disabled_dec(void)
  11387. +{
  11388. + current->pagefault_disabled--;
  11389. + WARN_ON(current->pagefault_disabled < 0);
  11390. +}
  11391. +
  11392. /*
  11393. - * These routines enable/disable the pagefault handler in that
  11394. - * it will not take any locks and go straight to the fixup table.
  11395. + * These routines enable/disable the pagefault handler. If disabled, it will
  11396. + * not take any locks and go straight to the fixup table.
  11397. *
  11398. - * They have great resemblance to the preempt_disable/enable calls
  11399. - * and in fact they are identical; this is because currently there is
  11400. - * no other way to make the pagefault handlers do this. So we do
  11401. - * disable preemption but we don't necessarily care about that.
  11402. + * User access methods will not sleep when called from a pagefault_disabled()
  11403. + * environment.
  11404. */
  11405. static inline void pagefault_disable(void)
  11406. {
  11407. - preempt_count_inc();
  11408. + migrate_disable();
  11409. + pagefault_disabled_inc();
  11410. /*
  11411. * make sure to have issued the store before a pagefault
  11412. * can hit.
  11413. @@ -25,18 +35,32 @@
  11414. static inline void pagefault_enable(void)
  11415. {
  11416. -#ifndef CONFIG_PREEMPT
  11417. /*
  11418. * make sure to issue those last loads/stores before enabling
  11419. * the pagefault handler again.
  11420. */
  11421. barrier();
  11422. - preempt_count_dec();
  11423. -#else
  11424. - preempt_enable();
  11425. -#endif
  11426. + pagefault_disabled_dec();
  11427. + migrate_enable();
  11428. }
  11429. +/*
  11430. + * Is the pagefault handler disabled? If so, user access methods will not sleep.
  11431. + */
  11432. +#define pagefault_disabled() (current->pagefault_disabled != 0)
  11433. +
  11434. +/*
  11435. + * The pagefault handler is in general disabled by pagefault_disable() or
  11436. + * when in irq context (via in_atomic()).
  11437. + *
  11438. + * This function should only be used by the fault handlers. Other users should
  11439. + * stick to pagefault_disabled().
  11440. + * Please NEVER use preempt_disable() to disable the fault handler. With
  11441. + * !CONFIG_PREEMPT_COUNT, this is like a NOP. So the handler won't be disabled.
  11442. + * in_atomic() will report different values based on !CONFIG_PREEMPT_COUNT.
  11443. + */
  11444. +#define faulthandler_disabled() (pagefault_disabled() || in_atomic())
  11445. +
  11446. #ifndef ARCH_HAS_NOCACHE_UACCESS
  11447. static inline unsigned long __copy_from_user_inatomic_nocache(void *to,
  11448. diff -Nur linux-4.1.6.orig/include/linux/uprobes.h linux-4.1.6/include/linux/uprobes.h
  11449. --- linux-4.1.6.orig/include/linux/uprobes.h 2015-08-17 05:52:51.000000000 +0200
  11450. +++ linux-4.1.6/include/linux/uprobes.h 2015-09-08 23:49:06.782014188 +0200
  11451. @@ -27,6 +27,7 @@
  11452. #include <linux/errno.h>
  11453. #include <linux/rbtree.h>
  11454. #include <linux/types.h>
  11455. +#include <linux/wait.h>
  11456. struct vm_area_struct;
  11457. struct mm_struct;
  11458. diff -Nur linux-4.1.6.orig/include/linux/vmstat.h linux-4.1.6/include/linux/vmstat.h
  11459. --- linux-4.1.6.orig/include/linux/vmstat.h 2015-08-17 05:52:51.000000000 +0200
  11460. +++ linux-4.1.6/include/linux/vmstat.h 2015-09-08 23:49:06.782014188 +0200
  11461. @@ -33,7 +33,9 @@
  11462. */
  11463. static inline void __count_vm_event(enum vm_event_item item)
  11464. {
  11465. + preempt_disable_rt();
  11466. raw_cpu_inc(vm_event_states.event[item]);
  11467. + preempt_enable_rt();
  11468. }
  11469. static inline void count_vm_event(enum vm_event_item item)
  11470. @@ -43,7 +45,9 @@
  11471. static inline void __count_vm_events(enum vm_event_item item, long delta)
  11472. {
  11473. + preempt_disable_rt();
  11474. raw_cpu_add(vm_event_states.event[item], delta);
  11475. + preempt_enable_rt();
  11476. }
  11477. static inline void count_vm_events(enum vm_event_item item, long delta)
  11478. diff -Nur linux-4.1.6.orig/include/linux/wait.h linux-4.1.6/include/linux/wait.h
  11479. --- linux-4.1.6.orig/include/linux/wait.h 2015-08-17 05:52:51.000000000 +0200
  11480. +++ linux-4.1.6/include/linux/wait.h 2015-09-08 23:49:06.786013744 +0200
  11481. @@ -8,6 +8,7 @@
  11482. #include <linux/spinlock.h>
  11483. #include <asm/current.h>
  11484. #include <uapi/linux/wait.h>
  11485. +#include <linux/atomic.h>
  11486. typedef struct __wait_queue wait_queue_t;
  11487. typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
  11488. diff -Nur linux-4.1.6.orig/include/linux/wait-simple.h linux-4.1.6/include/linux/wait-simple.h
  11489. --- linux-4.1.6.orig/include/linux/wait-simple.h 1970-01-01 01:00:00.000000000 +0100
  11490. +++ linux-4.1.6/include/linux/wait-simple.h 2015-09-08 23:49:06.786013744 +0200
  11491. @@ -0,0 +1,207 @@
  11492. +#ifndef _LINUX_WAIT_SIMPLE_H
  11493. +#define _LINUX_WAIT_SIMPLE_H
  11494. +
  11495. +#include <linux/spinlock.h>
  11496. +#include <linux/list.h>
  11497. +
  11498. +#include <asm/current.h>
  11499. +
  11500. +struct swaiter {
  11501. + struct task_struct *task;
  11502. + struct list_head node;
  11503. +};
  11504. +
  11505. +#define DEFINE_SWAITER(name) \
  11506. + struct swaiter name = { \
  11507. + .task = current, \
  11508. + .node = LIST_HEAD_INIT((name).node), \
  11509. + }
  11510. +
  11511. +struct swait_head {
  11512. + raw_spinlock_t lock;
  11513. + struct list_head list;
  11514. +};
  11515. +
  11516. +#define SWAIT_HEAD_INITIALIZER(name) { \
  11517. + .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
  11518. + .list = LIST_HEAD_INIT((name).list), \
  11519. + }
  11520. +
  11521. +#define DEFINE_SWAIT_HEAD(name) \
  11522. + struct swait_head name = SWAIT_HEAD_INITIALIZER(name)
  11523. +
  11524. +extern void __init_swait_head(struct swait_head *h, struct lock_class_key *key);
  11525. +
  11526. +#define init_swait_head(swh) \
  11527. + do { \
  11528. + static struct lock_class_key __key; \
  11529. + \
  11530. + __init_swait_head((swh), &__key); \
  11531. + } while (0)
  11532. +
  11533. +/*
  11534. + * Waiter functions
  11535. + */
  11536. +extern void swait_prepare_locked(struct swait_head *head, struct swaiter *w);
  11537. +extern void swait_prepare(struct swait_head *head, struct swaiter *w, int state);
  11538. +extern void swait_finish_locked(struct swait_head *head, struct swaiter *w);
  11539. +extern void swait_finish(struct swait_head *head, struct swaiter *w);
  11540. +
  11541. +/* Check whether a head has waiters enqueued */
  11542. +static inline bool swaitqueue_active(struct swait_head *h)
  11543. +{
  11544. + /* Make sure the condition is visible before checking list_empty() */
  11545. + smp_mb();
  11546. + return !list_empty(&h->list);
  11547. +}
  11548. +
  11549. +/*
  11550. + * Wakeup functions
  11551. + */
  11552. +extern unsigned int __swait_wake(struct swait_head *head, unsigned int state, unsigned int num);
  11553. +extern unsigned int __swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num);
  11554. +
  11555. +#define swait_wake(head) __swait_wake(head, TASK_NORMAL, 1)
  11556. +#define swait_wake_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 1)
  11557. +#define swait_wake_all(head) __swait_wake(head, TASK_NORMAL, 0)
  11558. +#define swait_wake_all_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 0)
  11559. +
  11560. +/*
  11561. + * Event API
  11562. + */
  11563. +#define __swait_event(wq, condition) \
  11564. +do { \
  11565. + DEFINE_SWAITER(__wait); \
  11566. + \
  11567. + for (;;) { \
  11568. + swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
  11569. + if (condition) \
  11570. + break; \
  11571. + schedule(); \
  11572. + } \
  11573. + swait_finish(&wq, &__wait); \
  11574. +} while (0)
  11575. +
  11576. +/**
  11577. + * swait_event - sleep until a condition gets true
  11578. + * @wq: the waitqueue to wait on
  11579. + * @condition: a C expression for the event to wait for
  11580. + *
  11581. + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  11582. + * @condition evaluates to true. The @condition is checked each time
  11583. + * the waitqueue @wq is woken up.
  11584. + *
  11585. + * wake_up() has to be called after changing any variable that could
  11586. + * change the result of the wait condition.
  11587. + */
  11588. +#define swait_event(wq, condition) \
  11589. +do { \
  11590. + if (condition) \
  11591. + break; \
  11592. + __swait_event(wq, condition); \
  11593. +} while (0)
  11594. +
  11595. +#define __swait_event_interruptible(wq, condition, ret) \
  11596. +do { \
  11597. + DEFINE_SWAITER(__wait); \
  11598. + \
  11599. + for (;;) { \
  11600. + swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
  11601. + if (condition) \
  11602. + break; \
  11603. + if (signal_pending(current)) { \
  11604. + ret = -ERESTARTSYS; \
  11605. + break; \
  11606. + } \
  11607. + schedule(); \
  11608. + } \
  11609. + swait_finish(&wq, &__wait); \
  11610. +} while (0)
  11611. +
  11612. +#define __swait_event_interruptible_timeout(wq, condition, ret) \
  11613. +do { \
  11614. + DEFINE_SWAITER(__wait); \
  11615. + \
  11616. + for (;;) { \
  11617. + swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
  11618. + if (condition) \
  11619. + break; \
  11620. + if (signal_pending(current)) { \
  11621. + ret = -ERESTARTSYS; \
  11622. + break; \
  11623. + } \
  11624. + ret = schedule_timeout(ret); \
  11625. + if (!ret) \
  11626. + break; \
  11627. + } \
  11628. + swait_finish(&wq, &__wait); \
  11629. +} while (0)
  11630. +
  11631. +/**
  11632. + * swait_event_interruptible - sleep until a condition gets true
  11633. + * @wq: the waitqueue to wait on
  11634. + * @condition: a C expression for the event to wait for
  11635. + *
  11636. + * The process is put to sleep (TASK_INTERRUPTIBLE) until the
  11637. + * @condition evaluates to true. The @condition is checked each time
  11638. + * the waitqueue @wq is woken up.
  11639. + *
  11640. + * wake_up() has to be called after changing any variable that could
  11641. + * change the result of the wait condition.
  11642. + */
  11643. +#define swait_event_interruptible(wq, condition) \
  11644. +({ \
  11645. + int __ret = 0; \
  11646. + if (!(condition)) \
  11647. + __swait_event_interruptible(wq, condition, __ret); \
  11648. + __ret; \
  11649. +})
  11650. +
  11651. +#define swait_event_interruptible_timeout(wq, condition, timeout) \
  11652. +({ \
  11653. + int __ret = timeout; \
  11654. + if (!(condition)) \
  11655. + __swait_event_interruptible_timeout(wq, condition, __ret); \
  11656. + __ret; \
  11657. +})
  11658. +
  11659. +#define __swait_event_timeout(wq, condition, ret) \
  11660. +do { \
  11661. + DEFINE_SWAITER(__wait); \
  11662. + \
  11663. + for (;;) { \
  11664. + swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
  11665. + if (condition) \
  11666. + break; \
  11667. + ret = schedule_timeout(ret); \
  11668. + if (!ret) \
  11669. + break; \
  11670. + } \
  11671. + swait_finish(&wq, &__wait); \
  11672. +} while (0)
  11673. +
  11674. +/**
  11675. + * swait_event_timeout - sleep until a condition gets true or a timeout elapses
  11676. + * @wq: the waitqueue to wait on
  11677. + * @condition: a C expression for the event to wait for
  11678. + * @timeout: timeout, in jiffies
  11679. + *
  11680. + * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
  11681. + * @condition evaluates to true. The @condition is checked each time
  11682. + * the waitqueue @wq is woken up.
  11683. + *
  11684. + * wake_up() has to be called after changing any variable that could
  11685. + * change the result of the wait condition.
  11686. + *
  11687. + * The function returns 0 if the @timeout elapsed, and the remaining
  11688. + * jiffies if the condition evaluated to true before the timeout elapsed.
  11689. + */
  11690. +#define swait_event_timeout(wq, condition, timeout) \
  11691. +({ \
  11692. + long __ret = timeout; \
  11693. + if (!(condition)) \
  11694. + __swait_event_timeout(wq, condition, __ret); \
  11695. + __ret; \
  11696. +})
  11697. +
  11698. +#endif
  11699. diff -Nur linux-4.1.6.orig/include/linux/work-simple.h linux-4.1.6/include/linux/work-simple.h
  11700. --- linux-4.1.6.orig/include/linux/work-simple.h 1970-01-01 01:00:00.000000000 +0100
  11701. +++ linux-4.1.6/include/linux/work-simple.h 2015-09-08 23:49:06.786013744 +0200
  11702. @@ -0,0 +1,24 @@
  11703. +#ifndef _LINUX_SWORK_H
  11704. +#define _LINUX_SWORK_H
  11705. +
  11706. +#include <linux/list.h>
  11707. +
  11708. +struct swork_event {
  11709. + struct list_head item;
  11710. + unsigned long flags;
  11711. + void (*func)(struct swork_event *);
  11712. +};
  11713. +
  11714. +static inline void INIT_SWORK(struct swork_event *event,
  11715. + void (*func)(struct swork_event *))
  11716. +{
  11717. + event->flags = 0;
  11718. + event->func = func;
  11719. +}
  11720. +
  11721. +bool swork_queue(struct swork_event *sev);
  11722. +
  11723. +int swork_get(void);
  11724. +void swork_put(void);
  11725. +
  11726. +#endif /* _LINUX_SWORK_H */
  11727. diff -Nur linux-4.1.6.orig/include/net/dst.h linux-4.1.6/include/net/dst.h
  11728. --- linux-4.1.6.orig/include/net/dst.h 2015-08-17 05:52:51.000000000 +0200
  11729. +++ linux-4.1.6/include/net/dst.h 2015-09-08 23:49:06.786013744 +0200
  11730. @@ -403,7 +403,7 @@
  11731. static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
  11732. struct sk_buff *skb)
  11733. {
  11734. - const struct hh_cache *hh;
  11735. + struct hh_cache *hh;
  11736. if (dst->pending_confirm) {
  11737. unsigned long now = jiffies;
  11738. diff -Nur linux-4.1.6.orig/include/net/neighbour.h linux-4.1.6/include/net/neighbour.h
  11739. --- linux-4.1.6.orig/include/net/neighbour.h 2015-08-17 05:52:51.000000000 +0200
  11740. +++ linux-4.1.6/include/net/neighbour.h 2015-09-08 23:49:07.409944556 +0200
  11741. @@ -445,7 +445,7 @@
  11742. }
  11743. #endif
  11744. -static inline int neigh_hh_output(const struct hh_cache *hh, struct sk_buff *skb)
  11745. +static inline int neigh_hh_output(struct hh_cache *hh, struct sk_buff *skb)
  11746. {
  11747. unsigned int seq;
  11748. int hh_len;
  11749. @@ -500,7 +500,7 @@
  11750. #define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
  11751. -static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
  11752. +static inline void neigh_ha_snapshot(char *dst, struct neighbour *n,
  11753. const struct net_device *dev)
  11754. {
  11755. unsigned int seq;
  11756. diff -Nur linux-4.1.6.orig/include/net/netns/ipv4.h linux-4.1.6/include/net/netns/ipv4.h
  11757. --- linux-4.1.6.orig/include/net/netns/ipv4.h 2015-08-17 05:52:51.000000000 +0200
  11758. +++ linux-4.1.6/include/net/netns/ipv4.h 2015-09-08 23:49:08.077870489 +0200
  11759. @@ -69,6 +69,7 @@
  11760. int sysctl_icmp_echo_ignore_all;
  11761. int sysctl_icmp_echo_ignore_broadcasts;
  11762. + int sysctl_icmp_echo_sysrq;
  11763. int sysctl_icmp_ignore_bogus_error_responses;
  11764. int sysctl_icmp_ratelimit;
  11765. int sysctl_icmp_ratemask;
  11766. diff -Nur linux-4.1.6.orig/include/trace/events/hist.h linux-4.1.6/include/trace/events/hist.h
  11767. --- linux-4.1.6.orig/include/trace/events/hist.h 1970-01-01 01:00:00.000000000 +0100
  11768. +++ linux-4.1.6/include/trace/events/hist.h 2015-09-08 23:49:08.077870489 +0200
  11769. @@ -0,0 +1,72 @@
  11770. +#undef TRACE_SYSTEM
  11771. +#define TRACE_SYSTEM hist
  11772. +
  11773. +#if !defined(_TRACE_HIST_H) || defined(TRACE_HEADER_MULTI_READ)
  11774. +#define _TRACE_HIST_H
  11775. +
  11776. +#include "latency_hist.h"
  11777. +#include <linux/tracepoint.h>
  11778. +
  11779. +#if !defined(CONFIG_PREEMPT_OFF_HIST) && !defined(CONFIG_INTERRUPT_OFF_HIST)
  11780. +#define trace_preemptirqsoff_hist(a, b)
  11781. +#else
  11782. +TRACE_EVENT(preemptirqsoff_hist,
  11783. +
  11784. + TP_PROTO(int reason, int starthist),
  11785. +
  11786. + TP_ARGS(reason, starthist),
  11787. +
  11788. + TP_STRUCT__entry(
  11789. + __field(int, reason)
  11790. + __field(int, starthist)
  11791. + ),
  11792. +
  11793. + TP_fast_assign(
  11794. + __entry->reason = reason;
  11795. + __entry->starthist = starthist;
  11796. + ),
  11797. +
  11798. + TP_printk("reason=%s starthist=%s", getaction(__entry->reason),
  11799. + __entry->starthist ? "start" : "stop")
  11800. +);
  11801. +#endif
  11802. +
  11803. +#ifndef CONFIG_MISSED_TIMER_OFFSETS_HIST
  11804. +#define trace_hrtimer_interrupt(a, b, c, d)
  11805. +#else
  11806. +TRACE_EVENT(hrtimer_interrupt,
  11807. +
  11808. + TP_PROTO(int cpu, long long offset, struct task_struct *curr,
  11809. + struct task_struct *task),
  11810. +
  11811. + TP_ARGS(cpu, offset, curr, task),
  11812. +
  11813. + TP_STRUCT__entry(
  11814. + __field(int, cpu)
  11815. + __field(long long, offset)
  11816. + __array(char, ccomm, TASK_COMM_LEN)
  11817. + __field(int, cprio)
  11818. + __array(char, tcomm, TASK_COMM_LEN)
  11819. + __field(int, tprio)
  11820. + ),
  11821. +
  11822. + TP_fast_assign(
  11823. + __entry->cpu = cpu;
  11824. + __entry->offset = offset;
  11825. + memcpy(__entry->ccomm, curr->comm, TASK_COMM_LEN);
  11826. + __entry->cprio = curr->prio;
  11827. + memcpy(__entry->tcomm, task != NULL ? task->comm : "<none>",
  11828. + task != NULL ? TASK_COMM_LEN : 7);
  11829. + __entry->tprio = task != NULL ? task->prio : -1;
  11830. + ),
  11831. +
  11832. + TP_printk("cpu=%d offset=%lld curr=%s[%d] thread=%s[%d]",
  11833. + __entry->cpu, __entry->offset, __entry->ccomm,
  11834. + __entry->cprio, __entry->tcomm, __entry->tprio)
  11835. +);
  11836. +#endif
  11837. +
  11838. +#endif /* _TRACE_HIST_H */
  11839. +
  11840. +/* This part must be outside protection */
  11841. +#include <trace/define_trace.h>
  11842. diff -Nur linux-4.1.6.orig/include/trace/events/latency_hist.h linux-4.1.6/include/trace/events/latency_hist.h
  11843. --- linux-4.1.6.orig/include/trace/events/latency_hist.h 1970-01-01 01:00:00.000000000 +0100
  11844. +++ linux-4.1.6/include/trace/events/latency_hist.h 2015-09-08 23:49:08.077870489 +0200
  11845. @@ -0,0 +1,29 @@
  11846. +#ifndef _LATENCY_HIST_H
  11847. +#define _LATENCY_HIST_H
  11848. +
  11849. +enum hist_action {
  11850. + IRQS_ON,
  11851. + PREEMPT_ON,
  11852. + TRACE_STOP,
  11853. + IRQS_OFF,
  11854. + PREEMPT_OFF,
  11855. + TRACE_START,
  11856. +};
  11857. +
  11858. +static char *actions[] = {
  11859. + "IRQS_ON",
  11860. + "PREEMPT_ON",
  11861. + "TRACE_STOP",
  11862. + "IRQS_OFF",
  11863. + "PREEMPT_OFF",
  11864. + "TRACE_START",
  11865. +};
  11866. +
  11867. +static inline char *getaction(int action)
  11868. +{
  11869. + if (action >= 0 && action <= sizeof(actions)/sizeof(actions[0]))
  11870. + return actions[action];
  11871. + return "unknown";
  11872. +}
  11873. +
  11874. +#endif /* _LATENCY_HIST_H */
  11875. diff -Nur linux-4.1.6.orig/init/Kconfig linux-4.1.6/init/Kconfig
  11876. --- linux-4.1.6.orig/init/Kconfig 2015-08-17 05:52:51.000000000 +0200
  11877. +++ linux-4.1.6/init/Kconfig 2015-09-08 23:49:08.077870489 +0200
  11878. @@ -637,7 +637,7 @@
  11879. config RCU_FAST_NO_HZ
  11880. bool "Accelerate last non-dyntick-idle CPU's grace periods"
  11881. - depends on NO_HZ_COMMON && SMP
  11882. + depends on NO_HZ_COMMON && SMP && !PREEMPT_RT_FULL
  11883. default n
  11884. help
  11885. This option permits CPUs to enter dynticks-idle state even if
  11886. @@ -664,7 +664,7 @@
  11887. config RCU_BOOST
  11888. bool "Enable RCU priority boosting"
  11889. depends on RT_MUTEXES && PREEMPT_RCU
  11890. - default n
  11891. + default y if PREEMPT_RT_FULL
  11892. help
  11893. This option boosts the priority of preempted RCU readers that
  11894. block the current preemptible RCU grace period for too long.
  11895. @@ -1101,6 +1101,7 @@
  11896. config RT_GROUP_SCHED
  11897. bool "Group scheduling for SCHED_RR/FIFO"
  11898. depends on CGROUP_SCHED
  11899. + depends on !PREEMPT_RT_FULL
  11900. default n
  11901. help
  11902. This feature lets you explicitly allocate real CPU bandwidth
  11903. @@ -1688,6 +1689,7 @@
  11904. config SLAB
  11905. bool "SLAB"
  11906. + depends on !PREEMPT_RT_FULL
  11907. help
  11908. The regular slab allocator that is established and known to work
  11909. well in all environments. It organizes cache hot objects in
  11910. @@ -1706,6 +1708,7 @@
  11911. config SLOB
  11912. depends on EXPERT
  11913. bool "SLOB (Simple Allocator)"
  11914. + depends on !PREEMPT_RT_FULL
  11915. help
  11916. SLOB replaces the stock allocator with a drastically simpler
  11917. allocator. SLOB is generally more space efficient but
  11918. @@ -1715,7 +1718,7 @@
  11919. config SLUB_CPU_PARTIAL
  11920. default y
  11921. - depends on SLUB && SMP
  11922. + depends on SLUB && SMP && !PREEMPT_RT_FULL
  11923. bool "SLUB per cpu partial cache"
  11924. help
  11925. Per cpu partial caches accellerate objects allocation and freeing
  11926. diff -Nur linux-4.1.6.orig/init/main.c linux-4.1.6/init/main.c
  11927. --- linux-4.1.6.orig/init/main.c 2015-08-17 05:52:51.000000000 +0200
  11928. +++ linux-4.1.6/init/main.c 2015-09-08 23:49:08.081870045 +0200
  11929. @@ -525,6 +525,7 @@
  11930. setup_command_line(command_line);
  11931. setup_nr_cpu_ids();
  11932. setup_per_cpu_areas();
  11933. + softirq_early_init();
  11934. smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
  11935. build_all_zonelists(NULL, NULL);
  11936. diff -Nur linux-4.1.6.orig/init/Makefile linux-4.1.6/init/Makefile
  11937. --- linux-4.1.6.orig/init/Makefile 2015-08-17 05:52:51.000000000 +0200
  11938. +++ linux-4.1.6/init/Makefile 2015-09-08 23:49:08.077870489 +0200
  11939. @@ -33,4 +33,4 @@
  11940. include/generated/compile.h: FORCE
  11941. @$($(quiet)chk_compile.h)
  11942. $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkcompile_h $@ \
  11943. - "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CC) $(KBUILD_CFLAGS)"
  11944. + "$(UTS_MACHINE)" "$(CONFIG_SMP)" "$(CONFIG_PREEMPT)" "$(CONFIG_PREEMPT_RT_FULL)" "$(CC) $(KBUILD_CFLAGS)"
  11945. diff -Nur linux-4.1.6.orig/ipc/mqueue.c linux-4.1.6/ipc/mqueue.c
  11946. --- linux-4.1.6.orig/ipc/mqueue.c 2015-08-17 05:52:51.000000000 +0200
  11947. +++ linux-4.1.6/ipc/mqueue.c 2015-09-08 23:49:08.081870045 +0200
  11948. @@ -47,8 +47,7 @@
  11949. #define RECV 1
  11950. #define STATE_NONE 0
  11951. -#define STATE_PENDING 1
  11952. -#define STATE_READY 2
  11953. +#define STATE_READY 1
  11954. struct posix_msg_tree_node {
  11955. struct rb_node rb_node;
  11956. @@ -568,15 +567,12 @@
  11957. wq_add(info, sr, ewp);
  11958. for (;;) {
  11959. - set_current_state(TASK_INTERRUPTIBLE);
  11960. + __set_current_state(TASK_INTERRUPTIBLE);
  11961. spin_unlock(&info->lock);
  11962. time = schedule_hrtimeout_range_clock(timeout, 0,
  11963. HRTIMER_MODE_ABS, CLOCK_REALTIME);
  11964. - while (ewp->state == STATE_PENDING)
  11965. - cpu_relax();
  11966. -
  11967. if (ewp->state == STATE_READY) {
  11968. retval = 0;
  11969. goto out;
  11970. @@ -904,11 +900,15 @@
  11971. * list of waiting receivers. A sender checks that list before adding the new
  11972. * message into the message array. If there is a waiting receiver, then it
  11973. * bypasses the message array and directly hands the message over to the
  11974. - * receiver.
  11975. - * The receiver accepts the message and returns without grabbing the queue
  11976. - * spinlock. Therefore an intermediate STATE_PENDING state and memory barriers
  11977. - * are necessary. The same algorithm is used for sysv semaphores, see
  11978. - * ipc/sem.c for more details.
  11979. + * receiver. The receiver accepts the message and returns without grabbing the
  11980. + * queue spinlock:
  11981. + *
  11982. + * - Set pointer to message.
  11983. + * - Queue the receiver task for later wakeup (without the info->lock).
  11984. + * - Update its state to STATE_READY. Now the receiver can continue.
  11985. + * - Wake up the process after the lock is dropped. Should the process wake up
  11986. + * before this wakeup (due to a timeout or a signal) it will either see
  11987. + * STATE_READY and continue or acquire the lock to check the state again.
  11988. *
  11989. * The same algorithm is used for senders.
  11990. */
  11991. @@ -916,21 +916,29 @@
  11992. /* pipelined_send() - send a message directly to the task waiting in
  11993. * sys_mq_timedreceive() (without inserting message into a queue).
  11994. */
  11995. -static inline void pipelined_send(struct mqueue_inode_info *info,
  11996. +static inline void pipelined_send(struct wake_q_head *wake_q,
  11997. + struct mqueue_inode_info *info,
  11998. struct msg_msg *message,
  11999. struct ext_wait_queue *receiver)
  12000. {
  12001. receiver->msg = message;
  12002. list_del(&receiver->list);
  12003. - receiver->state = STATE_PENDING;
  12004. - wake_up_process(receiver->task);
  12005. - smp_wmb();
  12006. + wake_q_add(wake_q, receiver->task);
  12007. + /*
  12008. + * Rely on the implicit cmpxchg barrier from wake_q_add such
  12009. + * that we can ensure that updating receiver->state is the last
  12010. + * write operation: As once set, the receiver can continue,
  12011. + * and if we don't have the reference count from the wake_q,
  12012. + * yet, at that point we can later have a use-after-free
  12013. + * condition and bogus wakeup.
  12014. + */
  12015. receiver->state = STATE_READY;
  12016. }
  12017. /* pipelined_receive() - if there is task waiting in sys_mq_timedsend()
  12018. * gets its message and put to the queue (we have one free place for sure). */
  12019. -static inline void pipelined_receive(struct mqueue_inode_info *info)
  12020. +static inline void pipelined_receive(struct wake_q_head *wake_q,
  12021. + struct mqueue_inode_info *info)
  12022. {
  12023. struct ext_wait_queue *sender = wq_get_first_waiter(info, SEND);
  12024. @@ -941,10 +949,9 @@
  12025. }
  12026. if (msg_insert(sender->msg, info))
  12027. return;
  12028. +
  12029. list_del(&sender->list);
  12030. - sender->state = STATE_PENDING;
  12031. - wake_up_process(sender->task);
  12032. - smp_wmb();
  12033. + wake_q_add(wake_q, sender->task);
  12034. sender->state = STATE_READY;
  12035. }
  12036. @@ -962,6 +969,7 @@
  12037. struct timespec ts;
  12038. struct posix_msg_tree_node *new_leaf = NULL;
  12039. int ret = 0;
  12040. + WAKE_Q(wake_q);
  12041. if (u_abs_timeout) {
  12042. int res = prepare_timeout(u_abs_timeout, &expires, &ts);
  12043. @@ -1045,7 +1053,7 @@
  12044. } else {
  12045. receiver = wq_get_first_waiter(info, RECV);
  12046. if (receiver) {
  12047. - pipelined_send(info, msg_ptr, receiver);
  12048. + pipelined_send(&wake_q, info, msg_ptr, receiver);
  12049. } else {
  12050. /* adds message to the queue */
  12051. ret = msg_insert(msg_ptr, info);
  12052. @@ -1058,6 +1066,7 @@
  12053. }
  12054. out_unlock:
  12055. spin_unlock(&info->lock);
  12056. + wake_up_q(&wake_q);
  12057. out_free:
  12058. if (ret)
  12059. free_msg(msg_ptr);
  12060. @@ -1144,14 +1153,17 @@
  12061. msg_ptr = wait.msg;
  12062. }
  12063. } else {
  12064. + WAKE_Q(wake_q);
  12065. +
  12066. msg_ptr = msg_get(info);
  12067. inode->i_atime = inode->i_mtime = inode->i_ctime =
  12068. CURRENT_TIME;
  12069. /* There is now free space in queue. */
  12070. - pipelined_receive(info);
  12071. + pipelined_receive(&wake_q, info);
  12072. spin_unlock(&info->lock);
  12073. + wake_up_q(&wake_q);
  12074. ret = 0;
  12075. }
  12076. if (ret == 0) {
  12077. diff -Nur linux-4.1.6.orig/ipc/msg.c linux-4.1.6/ipc/msg.c
  12078. --- linux-4.1.6.orig/ipc/msg.c 2015-08-17 05:52:51.000000000 +0200
  12079. +++ linux-4.1.6/ipc/msg.c 2015-09-08 23:49:08.081870045 +0200
  12080. @@ -188,6 +188,12 @@
  12081. struct msg_receiver *msr, *t;
  12082. list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
  12083. + /*
  12084. + * Make sure that the wakeup doesnt preempt
  12085. + * this CPU prematurely. (on PREEMPT_RT)
  12086. + */
  12087. + preempt_disable_rt();
  12088. +
  12089. msr->r_msg = NULL; /* initialize expunge ordering */
  12090. wake_up_process(msr->r_tsk);
  12091. /*
  12092. @@ -198,6 +204,8 @@
  12093. */
  12094. smp_mb();
  12095. msr->r_msg = ERR_PTR(res);
  12096. +
  12097. + preempt_enable_rt();
  12098. }
  12099. }
  12100. @@ -574,6 +582,11 @@
  12101. if (testmsg(msg, msr->r_msgtype, msr->r_mode) &&
  12102. !security_msg_queue_msgrcv(msq, msg, msr->r_tsk,
  12103. msr->r_msgtype, msr->r_mode)) {
  12104. + /*
  12105. + * Make sure that the wakeup doesnt preempt
  12106. + * this CPU prematurely. (on PREEMPT_RT)
  12107. + */
  12108. + preempt_disable_rt();
  12109. list_del(&msr->r_list);
  12110. if (msr->r_maxsize < msg->m_ts) {
  12111. @@ -595,12 +608,13 @@
  12112. */
  12113. smp_mb();
  12114. msr->r_msg = msg;
  12115. + preempt_enable_rt();
  12116. return 1;
  12117. }
  12118. + preempt_enable_rt();
  12119. }
  12120. }
  12121. -
  12122. return 0;
  12123. }
  12124. diff -Nur linux-4.1.6.orig/ipc/sem.c linux-4.1.6/ipc/sem.c
  12125. --- linux-4.1.6.orig/ipc/sem.c 2015-08-17 05:52:51.000000000 +0200
  12126. +++ linux-4.1.6/ipc/sem.c 2015-09-08 23:49:08.085869602 +0200
  12127. @@ -680,6 +680,13 @@
  12128. static void wake_up_sem_queue_prepare(struct list_head *pt,
  12129. struct sem_queue *q, int error)
  12130. {
  12131. +#ifdef CONFIG_PREEMPT_RT_BASE
  12132. + struct task_struct *p = q->sleeper;
  12133. + get_task_struct(p);
  12134. + q->status = error;
  12135. + wake_up_process(p);
  12136. + put_task_struct(p);
  12137. +#else
  12138. if (list_empty(pt)) {
  12139. /*
  12140. * Hold preempt off so that we don't get preempted and have the
  12141. @@ -691,6 +698,7 @@
  12142. q->pid = error;
  12143. list_add_tail(&q->list, pt);
  12144. +#endif
  12145. }
  12146. /**
  12147. @@ -704,6 +712,7 @@
  12148. */
  12149. static void wake_up_sem_queue_do(struct list_head *pt)
  12150. {
  12151. +#ifndef CONFIG_PREEMPT_RT_BASE
  12152. struct sem_queue *q, *t;
  12153. int did_something;
  12154. @@ -716,6 +725,7 @@
  12155. }
  12156. if (did_something)
  12157. preempt_enable();
  12158. +#endif
  12159. }
  12160. static void unlink_queue(struct sem_array *sma, struct sem_queue *q)
  12161. diff -Nur linux-4.1.6.orig/kernel/cgroup.c linux-4.1.6/kernel/cgroup.c
  12162. --- linux-4.1.6.orig/kernel/cgroup.c 2015-08-17 05:52:51.000000000 +0200
  12163. +++ linux-4.1.6/kernel/cgroup.c 2015-09-08 23:49:08.089869160 +0200
  12164. @@ -4421,10 +4421,10 @@
  12165. queue_work(cgroup_destroy_wq, &css->destroy_work);
  12166. }
  12167. -static void css_release_work_fn(struct work_struct *work)
  12168. +static void css_release_work_fn(struct swork_event *sev)
  12169. {
  12170. struct cgroup_subsys_state *css =
  12171. - container_of(work, struct cgroup_subsys_state, destroy_work);
  12172. + container_of(sev, struct cgroup_subsys_state, destroy_swork);
  12173. struct cgroup_subsys *ss = css->ss;
  12174. struct cgroup *cgrp = css->cgroup;
  12175. @@ -4463,8 +4463,8 @@
  12176. struct cgroup_subsys_state *css =
  12177. container_of(ref, struct cgroup_subsys_state, refcnt);
  12178. - INIT_WORK(&css->destroy_work, css_release_work_fn);
  12179. - queue_work(cgroup_destroy_wq, &css->destroy_work);
  12180. + INIT_SWORK(&css->destroy_swork, css_release_work_fn);
  12181. + swork_queue(&css->destroy_swork);
  12182. }
  12183. static void init_and_link_css(struct cgroup_subsys_state *css,
  12184. @@ -5068,6 +5068,7 @@
  12185. */
  12186. cgroup_destroy_wq = alloc_workqueue("cgroup_destroy", 0, 1);
  12187. BUG_ON(!cgroup_destroy_wq);
  12188. + BUG_ON(swork_get());
  12189. /*
  12190. * Used to destroy pidlists and separate to serve as flush domain.
  12191. diff -Nur linux-4.1.6.orig/kernel/cpu.c linux-4.1.6/kernel/cpu.c
  12192. --- linux-4.1.6.orig/kernel/cpu.c 2015-08-17 05:52:51.000000000 +0200
  12193. +++ linux-4.1.6/kernel/cpu.c 2015-09-08 23:49:08.089869160 +0200
  12194. @@ -74,8 +74,8 @@
  12195. #endif
  12196. } cpu_hotplug = {
  12197. .active_writer = NULL,
  12198. - .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  12199. .lock = __MUTEX_INITIALIZER(cpu_hotplug.lock),
  12200. + .wq = __WAIT_QUEUE_HEAD_INITIALIZER(cpu_hotplug.wq),
  12201. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  12202. .dep_map = {.name = "cpu_hotplug.lock" },
  12203. #endif
  12204. @@ -88,6 +88,289 @@
  12205. #define cpuhp_lock_acquire() lock_map_acquire(&cpu_hotplug.dep_map)
  12206. #define cpuhp_lock_release() lock_map_release(&cpu_hotplug.dep_map)
  12207. +/**
  12208. + * hotplug_pcp - per cpu hotplug descriptor
  12209. + * @unplug: set when pin_current_cpu() needs to sync tasks
  12210. + * @sync_tsk: the task that waits for tasks to finish pinned sections
  12211. + * @refcount: counter of tasks in pinned sections
  12212. + * @grab_lock: set when the tasks entering pinned sections should wait
  12213. + * @synced: notifier for @sync_tsk to tell cpu_down it's finished
  12214. + * @mutex: the mutex to make tasks wait (used when @grab_lock is true)
  12215. + * @mutex_init: zero if the mutex hasn't been initialized yet.
  12216. + *
  12217. + * Although @unplug and @sync_tsk may point to the same task, the @unplug
  12218. + * is used as a flag and still exists after @sync_tsk has exited and
  12219. + * @sync_tsk set to NULL.
  12220. + */
  12221. +struct hotplug_pcp {
  12222. + struct task_struct *unplug;
  12223. + struct task_struct *sync_tsk;
  12224. + int refcount;
  12225. + int grab_lock;
  12226. + struct completion synced;
  12227. + struct completion unplug_wait;
  12228. +#ifdef CONFIG_PREEMPT_RT_FULL
  12229. + /*
  12230. + * Note, on PREEMPT_RT, the hotplug lock must save the state of
  12231. + * the task, otherwise the mutex will cause the task to fail
  12232. + * to sleep when required. (Because it's called from migrate_disable())
  12233. + *
  12234. + * The spinlock_t on PREEMPT_RT is a mutex that saves the task's
  12235. + * state.
  12236. + */
  12237. + spinlock_t lock;
  12238. +#else
  12239. + struct mutex mutex;
  12240. +#endif
  12241. + int mutex_init;
  12242. +};
  12243. +
  12244. +#ifdef CONFIG_PREEMPT_RT_FULL
  12245. +# define hotplug_lock(hp) rt_spin_lock(&(hp)->lock)
  12246. +# define hotplug_unlock(hp) rt_spin_unlock(&(hp)->lock)
  12247. +#else
  12248. +# define hotplug_lock(hp) mutex_lock(&(hp)->mutex)
  12249. +# define hotplug_unlock(hp) mutex_unlock(&(hp)->mutex)
  12250. +#endif
  12251. +
  12252. +static DEFINE_PER_CPU(struct hotplug_pcp, hotplug_pcp);
  12253. +
  12254. +/**
  12255. + * pin_current_cpu - Prevent the current cpu from being unplugged
  12256. + *
  12257. + * Lightweight version of get_online_cpus() to prevent cpu from being
  12258. + * unplugged when code runs in a migration disabled region.
  12259. + *
  12260. + * Must be called with preemption disabled (preempt_count = 1)!
  12261. + */
  12262. +void pin_current_cpu(void)
  12263. +{
  12264. + struct hotplug_pcp *hp;
  12265. + int force = 0;
  12266. +
  12267. +retry:
  12268. + hp = this_cpu_ptr(&hotplug_pcp);
  12269. +
  12270. + if (!hp->unplug || hp->refcount || force || preempt_count() > 1 ||
  12271. + hp->unplug == current) {
  12272. + hp->refcount++;
  12273. + return;
  12274. + }
  12275. + if (hp->grab_lock) {
  12276. + preempt_enable();
  12277. + hotplug_lock(hp);
  12278. + hotplug_unlock(hp);
  12279. + } else {
  12280. + preempt_enable();
  12281. + /*
  12282. + * Try to push this task off of this CPU.
  12283. + */
  12284. + if (!migrate_me()) {
  12285. + preempt_disable();
  12286. + hp = this_cpu_ptr(&hotplug_pcp);
  12287. + if (!hp->grab_lock) {
  12288. + /*
  12289. + * Just let it continue it's already pinned
  12290. + * or about to sleep.
  12291. + */
  12292. + force = 1;
  12293. + goto retry;
  12294. + }
  12295. + preempt_enable();
  12296. + }
  12297. + }
  12298. + preempt_disable();
  12299. + goto retry;
  12300. +}
  12301. +
  12302. +/**
  12303. + * unpin_current_cpu - Allow unplug of current cpu
  12304. + *
  12305. + * Must be called with preemption or interrupts disabled!
  12306. + */
  12307. +void unpin_current_cpu(void)
  12308. +{
  12309. + struct hotplug_pcp *hp = this_cpu_ptr(&hotplug_pcp);
  12310. +
  12311. + WARN_ON(hp->refcount <= 0);
  12312. +
  12313. + /* This is safe. sync_unplug_thread is pinned to this cpu */
  12314. + if (!--hp->refcount && hp->unplug && hp->unplug != current)
  12315. + wake_up_process(hp->unplug);
  12316. +}
  12317. +
  12318. +static void wait_for_pinned_cpus(struct hotplug_pcp *hp)
  12319. +{
  12320. + set_current_state(TASK_UNINTERRUPTIBLE);
  12321. + while (hp->refcount) {
  12322. + schedule_preempt_disabled();
  12323. + set_current_state(TASK_UNINTERRUPTIBLE);
  12324. + }
  12325. +}
  12326. +
  12327. +static int sync_unplug_thread(void *data)
  12328. +{
  12329. + struct hotplug_pcp *hp = data;
  12330. +
  12331. + wait_for_completion(&hp->unplug_wait);
  12332. + preempt_disable();
  12333. + hp->unplug = current;
  12334. + wait_for_pinned_cpus(hp);
  12335. +
  12336. + /*
  12337. + * This thread will synchronize the cpu_down() with threads
  12338. + * that have pinned the CPU. When the pinned CPU count reaches
  12339. + * zero, we inform the cpu_down code to continue to the next step.
  12340. + */
  12341. + set_current_state(TASK_UNINTERRUPTIBLE);
  12342. + preempt_enable();
  12343. + complete(&hp->synced);
  12344. +
  12345. + /*
  12346. + * If all succeeds, the next step will need tasks to wait till
  12347. + * the CPU is offline before continuing. To do this, the grab_lock
  12348. + * is set and tasks going into pin_current_cpu() will block on the
  12349. + * mutex. But we still need to wait for those that are already in
  12350. + * pinned CPU sections. If the cpu_down() failed, the kthread_should_stop()
  12351. + * will kick this thread out.
  12352. + */
  12353. + while (!hp->grab_lock && !kthread_should_stop()) {
  12354. + schedule();
  12355. + set_current_state(TASK_UNINTERRUPTIBLE);
  12356. + }
  12357. +
  12358. + /* Make sure grab_lock is seen before we see a stale completion */
  12359. + smp_mb();
  12360. +
  12361. + /*
  12362. + * Now just before cpu_down() enters stop machine, we need to make
  12363. + * sure all tasks that are in pinned CPU sections are out, and new
  12364. + * tasks will now grab the lock, keeping them from entering pinned
  12365. + * CPU sections.
  12366. + */
  12367. + if (!kthread_should_stop()) {
  12368. + preempt_disable();
  12369. + wait_for_pinned_cpus(hp);
  12370. + preempt_enable();
  12371. + complete(&hp->synced);
  12372. + }
  12373. +
  12374. + set_current_state(TASK_UNINTERRUPTIBLE);
  12375. + while (!kthread_should_stop()) {
  12376. + schedule();
  12377. + set_current_state(TASK_UNINTERRUPTIBLE);
  12378. + }
  12379. + set_current_state(TASK_RUNNING);
  12380. +
  12381. + /*
  12382. + * Force this thread off this CPU as it's going down and
  12383. + * we don't want any more work on this CPU.
  12384. + */
  12385. + current->flags &= ~PF_NO_SETAFFINITY;
  12386. + set_cpus_allowed_ptr(current, cpu_present_mask);
  12387. + migrate_me();
  12388. + return 0;
  12389. +}
  12390. +
  12391. +static void __cpu_unplug_sync(struct hotplug_pcp *hp)
  12392. +{
  12393. + wake_up_process(hp->sync_tsk);
  12394. + wait_for_completion(&hp->synced);
  12395. +}
  12396. +
  12397. +static void __cpu_unplug_wait(unsigned int cpu)
  12398. +{
  12399. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  12400. +
  12401. + complete(&hp->unplug_wait);
  12402. + wait_for_completion(&hp->synced);
  12403. +}
  12404. +
  12405. +/*
  12406. + * Start the sync_unplug_thread on the target cpu and wait for it to
  12407. + * complete.
  12408. + */
  12409. +static int cpu_unplug_begin(unsigned int cpu)
  12410. +{
  12411. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  12412. + int err;
  12413. +
  12414. + /* Protected by cpu_hotplug.lock */
  12415. + if (!hp->mutex_init) {
  12416. +#ifdef CONFIG_PREEMPT_RT_FULL
  12417. + spin_lock_init(&hp->lock);
  12418. +#else
  12419. + mutex_init(&hp->mutex);
  12420. +#endif
  12421. + hp->mutex_init = 1;
  12422. + }
  12423. +
  12424. + /* Inform the scheduler to migrate tasks off this CPU */
  12425. + tell_sched_cpu_down_begin(cpu);
  12426. +
  12427. + init_completion(&hp->synced);
  12428. + init_completion(&hp->unplug_wait);
  12429. +
  12430. + hp->sync_tsk = kthread_create(sync_unplug_thread, hp, "sync_unplug/%d", cpu);
  12431. + if (IS_ERR(hp->sync_tsk)) {
  12432. + err = PTR_ERR(hp->sync_tsk);
  12433. + hp->sync_tsk = NULL;
  12434. + return err;
  12435. + }
  12436. + kthread_bind(hp->sync_tsk, cpu);
  12437. +
  12438. + /*
  12439. + * Wait for tasks to get out of the pinned sections,
  12440. + * it's still OK if new tasks enter. Some CPU notifiers will
  12441. + * wait for tasks that are going to enter these sections and
  12442. + * we must not have them block.
  12443. + */
  12444. + wake_up_process(hp->sync_tsk);
  12445. + return 0;
  12446. +}
  12447. +
  12448. +static void cpu_unplug_sync(unsigned int cpu)
  12449. +{
  12450. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  12451. +
  12452. + init_completion(&hp->synced);
  12453. + /* The completion needs to be initialzied before setting grab_lock */
  12454. + smp_wmb();
  12455. +
  12456. + /* Grab the mutex before setting grab_lock */
  12457. + hotplug_lock(hp);
  12458. + hp->grab_lock = 1;
  12459. +
  12460. + /*
  12461. + * The CPU notifiers have been completed.
  12462. + * Wait for tasks to get out of pinned CPU sections and have new
  12463. + * tasks block until the CPU is completely down.
  12464. + */
  12465. + __cpu_unplug_sync(hp);
  12466. +
  12467. + /* All done with the sync thread */
  12468. + kthread_stop(hp->sync_tsk);
  12469. + hp->sync_tsk = NULL;
  12470. +}
  12471. +
  12472. +static void cpu_unplug_done(unsigned int cpu)
  12473. +{
  12474. + struct hotplug_pcp *hp = &per_cpu(hotplug_pcp, cpu);
  12475. +
  12476. + hp->unplug = NULL;
  12477. + /* Let all tasks know cpu unplug is finished before cleaning up */
  12478. + smp_wmb();
  12479. +
  12480. + if (hp->sync_tsk)
  12481. + kthread_stop(hp->sync_tsk);
  12482. +
  12483. + if (hp->grab_lock) {
  12484. + hotplug_unlock(hp);
  12485. + /* protected by cpu_hotplug.lock */
  12486. + hp->grab_lock = 0;
  12487. + }
  12488. + tell_sched_cpu_down_done(cpu);
  12489. +}
  12490. void get_online_cpus(void)
  12491. {
  12492. @@ -349,13 +632,15 @@
  12493. /* Requires cpu_add_remove_lock to be held */
  12494. static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
  12495. {
  12496. - int err, nr_calls = 0;
  12497. + int mycpu, err, nr_calls = 0;
  12498. void *hcpu = (void *)(long)cpu;
  12499. unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
  12500. struct take_cpu_down_param tcd_param = {
  12501. .mod = mod,
  12502. .hcpu = hcpu,
  12503. };
  12504. + cpumask_var_t cpumask;
  12505. + cpumask_var_t cpumask_org;
  12506. if (num_online_cpus() == 1)
  12507. return -EBUSY;
  12508. @@ -363,7 +648,34 @@
  12509. if (!cpu_online(cpu))
  12510. return -EINVAL;
  12511. + /* Move the downtaker off the unplug cpu */
  12512. + if (!alloc_cpumask_var(&cpumask, GFP_KERNEL))
  12513. + return -ENOMEM;
  12514. + if (!alloc_cpumask_var(&cpumask_org, GFP_KERNEL)) {
  12515. + free_cpumask_var(cpumask);
  12516. + return -ENOMEM;
  12517. + }
  12518. +
  12519. + cpumask_copy(cpumask_org, tsk_cpus_allowed(current));
  12520. + cpumask_andnot(cpumask, cpu_online_mask, cpumask_of(cpu));
  12521. + set_cpus_allowed_ptr(current, cpumask);
  12522. + free_cpumask_var(cpumask);
  12523. + migrate_disable();
  12524. + mycpu = smp_processor_id();
  12525. + if (mycpu == cpu) {
  12526. + printk(KERN_ERR "Yuck! Still on unplug CPU\n!");
  12527. + migrate_enable();
  12528. + err = -EBUSY;
  12529. + goto restore_cpus;
  12530. + }
  12531. + migrate_enable();
  12532. +
  12533. cpu_hotplug_begin();
  12534. + err = cpu_unplug_begin(cpu);
  12535. + if (err) {
  12536. + printk("cpu_unplug_begin(%d) failed\n", cpu);
  12537. + goto out_cancel;
  12538. + }
  12539. err = __cpu_notify(CPU_DOWN_PREPARE | mod, hcpu, -1, &nr_calls);
  12540. if (err) {
  12541. @@ -389,8 +701,12 @@
  12542. #endif
  12543. synchronize_rcu();
  12544. + __cpu_unplug_wait(cpu);
  12545. smpboot_park_threads(cpu);
  12546. + /* Notifiers are done. Don't let any more tasks pin this CPU. */
  12547. + cpu_unplug_sync(cpu);
  12548. +
  12549. /*
  12550. * So now all preempt/rcu users must observe !cpu_active().
  12551. */
  12552. @@ -427,9 +743,14 @@
  12553. check_for_tasks(cpu);
  12554. out_release:
  12555. + cpu_unplug_done(cpu);
  12556. +out_cancel:
  12557. cpu_hotplug_done();
  12558. if (!err)
  12559. cpu_notify_nofail(CPU_POST_DEAD | mod, hcpu);
  12560. +restore_cpus:
  12561. + set_cpus_allowed_ptr(current, cpumask_org);
  12562. + free_cpumask_var(cpumask_org);
  12563. return err;
  12564. }
  12565. diff -Nur linux-4.1.6.orig/kernel/debug/kdb/kdb_io.c linux-4.1.6/kernel/debug/kdb/kdb_io.c
  12566. --- linux-4.1.6.orig/kernel/debug/kdb/kdb_io.c 2015-08-17 05:52:51.000000000 +0200
  12567. +++ linux-4.1.6/kernel/debug/kdb/kdb_io.c 2015-09-08 23:49:08.089869160 +0200
  12568. @@ -554,7 +554,6 @@
  12569. int linecount;
  12570. int colcount;
  12571. int logging, saved_loglevel = 0;
  12572. - int saved_trap_printk;
  12573. int got_printf_lock = 0;
  12574. int retlen = 0;
  12575. int fnd, len;
  12576. @@ -565,8 +564,6 @@
  12577. unsigned long uninitialized_var(flags);
  12578. preempt_disable();
  12579. - saved_trap_printk = kdb_trap_printk;
  12580. - kdb_trap_printk = 0;
  12581. /* Serialize kdb_printf if multiple cpus try to write at once.
  12582. * But if any cpu goes recursive in kdb, just print the output,
  12583. @@ -855,7 +852,6 @@
  12584. } else {
  12585. __release(kdb_printf_lock);
  12586. }
  12587. - kdb_trap_printk = saved_trap_printk;
  12588. preempt_enable();
  12589. return retlen;
  12590. }
  12591. @@ -865,9 +861,11 @@
  12592. va_list ap;
  12593. int r;
  12594. + kdb_trap_printk++;
  12595. va_start(ap, fmt);
  12596. r = vkdb_printf(KDB_MSGSRC_INTERNAL, fmt, ap);
  12597. va_end(ap);
  12598. + kdb_trap_printk--;
  12599. return r;
  12600. }
  12601. diff -Nur linux-4.1.6.orig/kernel/events/core.c linux-4.1.6/kernel/events/core.c
  12602. --- linux-4.1.6.orig/kernel/events/core.c 2015-08-17 05:52:51.000000000 +0200
  12603. +++ linux-4.1.6/kernel/events/core.c 2015-09-08 23:49:08.089869160 +0200
  12604. @@ -6890,6 +6890,7 @@
  12605. hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  12606. hwc->hrtimer.function = perf_swevent_hrtimer;
  12607. + hwc->hrtimer.irqsafe = 1;
  12608. /*
  12609. * Since hrtimers have a fixed rate, we can do a static freq->period
  12610. diff -Nur linux-4.1.6.orig/kernel/exit.c linux-4.1.6/kernel/exit.c
  12611. --- linux-4.1.6.orig/kernel/exit.c 2015-08-17 05:52:51.000000000 +0200
  12612. +++ linux-4.1.6/kernel/exit.c 2015-09-08 23:49:08.089869160 +0200
  12613. @@ -144,7 +144,7 @@
  12614. * Do this under ->siglock, we can race with another thread
  12615. * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
  12616. */
  12617. - flush_sigqueue(&tsk->pending);
  12618. + flush_task_sigqueue(tsk);
  12619. tsk->sighand = NULL;
  12620. spin_unlock(&sighand->siglock);
  12621. diff -Nur linux-4.1.6.orig/kernel/fork.c linux-4.1.6/kernel/fork.c
  12622. --- linux-4.1.6.orig/kernel/fork.c 2015-08-17 05:52:51.000000000 +0200
  12623. +++ linux-4.1.6/kernel/fork.c 2015-09-08 23:49:08.089869160 +0200
  12624. @@ -108,7 +108,7 @@
  12625. DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  12626. -__cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
  12627. +DEFINE_RWLOCK(tasklist_lock); /* outer */
  12628. #ifdef CONFIG_PROVE_RCU
  12629. int lockdep_tasklist_lock_is_held(void)
  12630. @@ -244,7 +244,9 @@
  12631. if (atomic_dec_and_test(&sig->sigcnt))
  12632. free_signal_struct(sig);
  12633. }
  12634. -
  12635. +#ifdef CONFIG_PREEMPT_RT_BASE
  12636. +static
  12637. +#endif
  12638. void __put_task_struct(struct task_struct *tsk)
  12639. {
  12640. WARN_ON(!tsk->exit_state);
  12641. @@ -260,7 +262,18 @@
  12642. if (!profile_handoff_task(tsk))
  12643. free_task(tsk);
  12644. }
  12645. +#ifndef CONFIG_PREEMPT_RT_BASE
  12646. EXPORT_SYMBOL_GPL(__put_task_struct);
  12647. +#else
  12648. +void __put_task_struct_cb(struct rcu_head *rhp)
  12649. +{
  12650. + struct task_struct *tsk = container_of(rhp, struct task_struct, put_rcu);
  12651. +
  12652. + __put_task_struct(tsk);
  12653. +
  12654. +}
  12655. +EXPORT_SYMBOL_GPL(__put_task_struct_cb);
  12656. +#endif
  12657. void __init __weak arch_task_cache_init(void) { }
  12658. @@ -680,6 +693,19 @@
  12659. }
  12660. EXPORT_SYMBOL_GPL(__mmdrop);
  12661. +#ifdef CONFIG_PREEMPT_RT_BASE
  12662. +/*
  12663. + * RCU callback for delayed mm drop. Not strictly rcu, but we don't
  12664. + * want another facility to make this work.
  12665. + */
  12666. +void __mmdrop_delayed(struct rcu_head *rhp)
  12667. +{
  12668. + struct mm_struct *mm = container_of(rhp, struct mm_struct, delayed_drop);
  12669. +
  12670. + __mmdrop(mm);
  12671. +}
  12672. +#endif
  12673. +
  12674. /*
  12675. * Decrement the use count and release all resources for an mm.
  12676. */
  12677. @@ -1214,6 +1240,9 @@
  12678. */
  12679. static void posix_cpu_timers_init(struct task_struct *tsk)
  12680. {
  12681. +#ifdef CONFIG_PREEMPT_RT_BASE
  12682. + tsk->posix_timer_list = NULL;
  12683. +#endif
  12684. tsk->cputime_expires.prof_exp = 0;
  12685. tsk->cputime_expires.virt_exp = 0;
  12686. tsk->cputime_expires.sched_exp = 0;
  12687. @@ -1338,6 +1367,7 @@
  12688. spin_lock_init(&p->alloc_lock);
  12689. init_sigpending(&p->pending);
  12690. + p->sigqueue_cache = NULL;
  12691. p->utime = p->stime = p->gtime = 0;
  12692. p->utimescaled = p->stimescaled = 0;
  12693. @@ -1345,7 +1375,8 @@
  12694. p->prev_cputime.utime = p->prev_cputime.stime = 0;
  12695. #endif
  12696. #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
  12697. - seqlock_init(&p->vtime_seqlock);
  12698. + raw_spin_lock_init(&p->vtime_lock);
  12699. + seqcount_init(&p->vtime_seq);
  12700. p->vtime_snap = 0;
  12701. p->vtime_snap_whence = VTIME_SLEEPING;
  12702. #endif
  12703. @@ -1396,6 +1427,9 @@
  12704. p->hardirq_context = 0;
  12705. p->softirq_context = 0;
  12706. #endif
  12707. +
  12708. + p->pagefault_disabled = 0;
  12709. +
  12710. #ifdef CONFIG_LOCKDEP
  12711. p->lockdep_depth = 0; /* no locks held yet */
  12712. p->curr_chain_key = 0;
  12713. diff -Nur linux-4.1.6.orig/kernel/futex.c linux-4.1.6/kernel/futex.c
  12714. --- linux-4.1.6.orig/kernel/futex.c 2015-08-17 05:52:51.000000000 +0200
  12715. +++ linux-4.1.6/kernel/futex.c 2015-09-08 23:49:08.089869160 +0200
  12716. @@ -738,7 +738,9 @@
  12717. * task still owns the PI-state:
  12718. */
  12719. if (head->next != next) {
  12720. + raw_spin_unlock_irq(&curr->pi_lock);
  12721. spin_unlock(&hb->lock);
  12722. + raw_spin_lock_irq(&curr->pi_lock);
  12723. continue;
  12724. }
  12725. @@ -1090,9 +1092,11 @@
  12726. /*
  12727. * The hash bucket lock must be held when this is called.
  12728. - * Afterwards, the futex_q must not be accessed.
  12729. + * Afterwards, the futex_q must not be accessed. Callers
  12730. + * must ensure to later call wake_up_q() for the actual
  12731. + * wakeups to occur.
  12732. */
  12733. -static void wake_futex(struct futex_q *q)
  12734. +static void mark_wake_futex(struct wake_q_head *wake_q, struct futex_q *q)
  12735. {
  12736. struct task_struct *p = q->task;
  12737. @@ -1100,14 +1104,10 @@
  12738. return;
  12739. /*
  12740. - * We set q->lock_ptr = NULL _before_ we wake up the task. If
  12741. - * a non-futex wake up happens on another CPU then the task
  12742. - * might exit and p would dereference a non-existing task
  12743. - * struct. Prevent this by holding a reference on p across the
  12744. - * wake up.
  12745. + * Queue the task for later wakeup for after we've released
  12746. + * the hb->lock. wake_q_add() grabs reference to p.
  12747. */
  12748. - get_task_struct(p);
  12749. -
  12750. + wake_q_add(wake_q, p);
  12751. __unqueue_futex(q);
  12752. /*
  12753. * The waiting task can free the futex_q as soon as
  12754. @@ -1117,16 +1117,15 @@
  12755. */
  12756. smp_wmb();
  12757. q->lock_ptr = NULL;
  12758. -
  12759. - wake_up_state(p, TASK_NORMAL);
  12760. - put_task_struct(p);
  12761. }
  12762. -static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this)
  12763. +static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
  12764. + struct futex_hash_bucket *hb)
  12765. {
  12766. struct task_struct *new_owner;
  12767. struct futex_pi_state *pi_state = this->pi_state;
  12768. u32 uninitialized_var(curval), newval;
  12769. + bool deboost;
  12770. int ret = 0;
  12771. if (!pi_state)
  12772. @@ -1178,7 +1177,17 @@
  12773. raw_spin_unlock_irq(&new_owner->pi_lock);
  12774. raw_spin_unlock(&pi_state->pi_mutex.wait_lock);
  12775. - rt_mutex_unlock(&pi_state->pi_mutex);
  12776. +
  12777. + deboost = rt_mutex_futex_unlock(&pi_state->pi_mutex);
  12778. +
  12779. + /*
  12780. + * We deboost after dropping hb->lock. That prevents a double
  12781. + * wakeup on RT.
  12782. + */
  12783. + spin_unlock(&hb->lock);
  12784. +
  12785. + if (deboost)
  12786. + rt_mutex_adjust_prio(current);
  12787. return 0;
  12788. }
  12789. @@ -1217,6 +1226,7 @@
  12790. struct futex_q *this, *next;
  12791. union futex_key key = FUTEX_KEY_INIT;
  12792. int ret;
  12793. + WAKE_Q(wake_q);
  12794. if (!bitset)
  12795. return -EINVAL;
  12796. @@ -1244,13 +1254,14 @@
  12797. if (!(this->bitset & bitset))
  12798. continue;
  12799. - wake_futex(this);
  12800. + mark_wake_futex(&wake_q, this);
  12801. if (++ret >= nr_wake)
  12802. break;
  12803. }
  12804. }
  12805. spin_unlock(&hb->lock);
  12806. + wake_up_q(&wake_q);
  12807. out_put_key:
  12808. put_futex_key(&key);
  12809. out:
  12810. @@ -1269,6 +1280,7 @@
  12811. struct futex_hash_bucket *hb1, *hb2;
  12812. struct futex_q *this, *next;
  12813. int ret, op_ret;
  12814. + WAKE_Q(wake_q);
  12815. retry:
  12816. ret = get_futex_key(uaddr1, flags & FLAGS_SHARED, &key1, VERIFY_READ);
  12817. @@ -1320,7 +1332,7 @@
  12818. ret = -EINVAL;
  12819. goto out_unlock;
  12820. }
  12821. - wake_futex(this);
  12822. + mark_wake_futex(&wake_q, this);
  12823. if (++ret >= nr_wake)
  12824. break;
  12825. }
  12826. @@ -1334,7 +1346,7 @@
  12827. ret = -EINVAL;
  12828. goto out_unlock;
  12829. }
  12830. - wake_futex(this);
  12831. + mark_wake_futex(&wake_q, this);
  12832. if (++op_ret >= nr_wake2)
  12833. break;
  12834. }
  12835. @@ -1344,6 +1356,7 @@
  12836. out_unlock:
  12837. double_unlock_hb(hb1, hb2);
  12838. + wake_up_q(&wake_q);
  12839. out_put_keys:
  12840. put_futex_key(&key2);
  12841. out_put_key1:
  12842. @@ -1503,6 +1516,7 @@
  12843. struct futex_pi_state *pi_state = NULL;
  12844. struct futex_hash_bucket *hb1, *hb2;
  12845. struct futex_q *this, *next;
  12846. + WAKE_Q(wake_q);
  12847. if (requeue_pi) {
  12848. /*
  12849. @@ -1679,7 +1693,7 @@
  12850. * woken by futex_unlock_pi().
  12851. */
  12852. if (++task_count <= nr_wake && !requeue_pi) {
  12853. - wake_futex(this);
  12854. + mark_wake_futex(&wake_q, this);
  12855. continue;
  12856. }
  12857. @@ -1705,6 +1719,16 @@
  12858. requeue_pi_wake_futex(this, &key2, hb2);
  12859. drop_count++;
  12860. continue;
  12861. + } else if (ret == -EAGAIN) {
  12862. + /*
  12863. + * Waiter was woken by timeout or
  12864. + * signal and has set pi_blocked_on to
  12865. + * PI_WAKEUP_INPROGRESS before we
  12866. + * tried to enqueue it on the rtmutex.
  12867. + */
  12868. + this->pi_state = NULL;
  12869. + free_pi_state(pi_state);
  12870. + continue;
  12871. } else if (ret) {
  12872. /* -EDEADLK */
  12873. this->pi_state = NULL;
  12874. @@ -1719,6 +1743,7 @@
  12875. out_unlock:
  12876. free_pi_state(pi_state);
  12877. double_unlock_hb(hb1, hb2);
  12878. + wake_up_q(&wake_q);
  12879. hb_waiters_dec(hb2);
  12880. /*
  12881. @@ -2412,13 +2437,26 @@
  12882. */
  12883. match = futex_top_waiter(hb, &key);
  12884. if (match) {
  12885. - ret = wake_futex_pi(uaddr, uval, match);
  12886. + ret = wake_futex_pi(uaddr, uval, match, hb);
  12887. +
  12888. + /*
  12889. + * In case of success wake_futex_pi dropped the hash
  12890. + * bucket lock.
  12891. + */
  12892. + if (!ret)
  12893. + goto out_putkey;
  12894. +
  12895. /*
  12896. * The atomic access to the futex value generated a
  12897. * pagefault, so retry the user-access and the wakeup:
  12898. */
  12899. if (ret == -EFAULT)
  12900. goto pi_faulted;
  12901. +
  12902. + /*
  12903. + * wake_futex_pi has detected invalid state. Tell user
  12904. + * space.
  12905. + */
  12906. goto out_unlock;
  12907. }
  12908. @@ -2439,6 +2477,7 @@
  12909. out_unlock:
  12910. spin_unlock(&hb->lock);
  12911. +out_putkey:
  12912. put_futex_key(&key);
  12913. return ret;
  12914. @@ -2549,7 +2588,7 @@
  12915. struct hrtimer_sleeper timeout, *to = NULL;
  12916. struct rt_mutex_waiter rt_waiter;
  12917. struct rt_mutex *pi_mutex = NULL;
  12918. - struct futex_hash_bucket *hb;
  12919. + struct futex_hash_bucket *hb, *hb2;
  12920. union futex_key key2 = FUTEX_KEY_INIT;
  12921. struct futex_q q = futex_q_init;
  12922. int res, ret;
  12923. @@ -2574,10 +2613,7 @@
  12924. * The waiter is allocated on our stack, manipulated by the requeue
  12925. * code while we sleep on uaddr.
  12926. */
  12927. - debug_rt_mutex_init_waiter(&rt_waiter);
  12928. - RB_CLEAR_NODE(&rt_waiter.pi_tree_entry);
  12929. - RB_CLEAR_NODE(&rt_waiter.tree_entry);
  12930. - rt_waiter.task = NULL;
  12931. + rt_mutex_init_waiter(&rt_waiter, false);
  12932. ret = get_futex_key(uaddr2, flags & FLAGS_SHARED, &key2, VERIFY_WRITE);
  12933. if (unlikely(ret != 0))
  12934. @@ -2608,20 +2644,55 @@
  12935. /* Queue the futex_q, drop the hb lock, wait for wakeup. */
  12936. futex_wait_queue_me(hb, &q, to);
  12937. - spin_lock(&hb->lock);
  12938. - ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  12939. - spin_unlock(&hb->lock);
  12940. - if (ret)
  12941. - goto out_put_keys;
  12942. + /*
  12943. + * On RT we must avoid races with requeue and trying to block
  12944. + * on two mutexes (hb->lock and uaddr2's rtmutex) by
  12945. + * serializing access to pi_blocked_on with pi_lock.
  12946. + */
  12947. + raw_spin_lock_irq(&current->pi_lock);
  12948. + if (current->pi_blocked_on) {
  12949. + /*
  12950. + * We have been requeued or are in the process of
  12951. + * being requeued.
  12952. + */
  12953. + raw_spin_unlock_irq(&current->pi_lock);
  12954. + } else {
  12955. + /*
  12956. + * Setting pi_blocked_on to PI_WAKEUP_INPROGRESS
  12957. + * prevents a concurrent requeue from moving us to the
  12958. + * uaddr2 rtmutex. After that we can safely acquire
  12959. + * (and possibly block on) hb->lock.
  12960. + */
  12961. + current->pi_blocked_on = PI_WAKEUP_INPROGRESS;
  12962. + raw_spin_unlock_irq(&current->pi_lock);
  12963. +
  12964. + spin_lock(&hb->lock);
  12965. +
  12966. + /*
  12967. + * Clean up pi_blocked_on. We might leak it otherwise
  12968. + * when we succeeded with the hb->lock in the fast
  12969. + * path.
  12970. + */
  12971. + raw_spin_lock_irq(&current->pi_lock);
  12972. + current->pi_blocked_on = NULL;
  12973. + raw_spin_unlock_irq(&current->pi_lock);
  12974. +
  12975. + ret = handle_early_requeue_pi_wakeup(hb, &q, &key2, to);
  12976. + spin_unlock(&hb->lock);
  12977. + if (ret)
  12978. + goto out_put_keys;
  12979. + }
  12980. /*
  12981. - * In order for us to be here, we know our q.key == key2, and since
  12982. - * we took the hb->lock above, we also know that futex_requeue() has
  12983. - * completed and we no longer have to concern ourselves with a wakeup
  12984. - * race with the atomic proxy lock acquisition by the requeue code. The
  12985. - * futex_requeue dropped our key1 reference and incremented our key2
  12986. - * reference count.
  12987. + * In order to be here, we have either been requeued, are in
  12988. + * the process of being requeued, or requeue successfully
  12989. + * acquired uaddr2 on our behalf. If pi_blocked_on was
  12990. + * non-null above, we may be racing with a requeue. Do not
  12991. + * rely on q->lock_ptr to be hb2->lock until after blocking on
  12992. + * hb->lock or hb2->lock. The futex_requeue dropped our key1
  12993. + * reference and incremented our key2 reference count.
  12994. */
  12995. + hb2 = hash_futex(&key2);
  12996. /* Check if the requeue code acquired the second futex for us. */
  12997. if (!q.rt_waiter) {
  12998. @@ -2630,9 +2701,10 @@
  12999. * did a lock-steal - fix up the PI-state in that case.
  13000. */
  13001. if (q.pi_state && (q.pi_state->owner != current)) {
  13002. - spin_lock(q.lock_ptr);
  13003. + spin_lock(&hb2->lock);
  13004. + BUG_ON(&hb2->lock != q.lock_ptr);
  13005. ret = fixup_pi_state_owner(uaddr2, &q, current);
  13006. - spin_unlock(q.lock_ptr);
  13007. + spin_unlock(&hb2->lock);
  13008. }
  13009. } else {
  13010. /*
  13011. @@ -2645,7 +2717,8 @@
  13012. ret = rt_mutex_finish_proxy_lock(pi_mutex, to, &rt_waiter);
  13013. debug_rt_mutex_free_waiter(&rt_waiter);
  13014. - spin_lock(q.lock_ptr);
  13015. + spin_lock(&hb2->lock);
  13016. + BUG_ON(&hb2->lock != q.lock_ptr);
  13017. /*
  13018. * Fixup the pi_state owner and possibly acquire the lock if we
  13019. * haven't already.
  13020. diff -Nur linux-4.1.6.orig/kernel/irq/handle.c linux-4.1.6/kernel/irq/handle.c
  13021. --- linux-4.1.6.orig/kernel/irq/handle.c 2015-08-17 05:52:51.000000000 +0200
  13022. +++ linux-4.1.6/kernel/irq/handle.c 2015-09-08 23:49:08.093868717 +0200
  13023. @@ -133,6 +133,8 @@
  13024. irqreturn_t
  13025. handle_irq_event_percpu(struct irq_desc *desc, struct irqaction *action)
  13026. {
  13027. + struct pt_regs *regs = get_irq_regs();
  13028. + u64 ip = regs ? instruction_pointer(regs) : 0;
  13029. irqreturn_t retval = IRQ_NONE;
  13030. unsigned int flags = 0, irq = desc->irq_data.irq;
  13031. @@ -173,7 +175,11 @@
  13032. action = action->next;
  13033. } while (action);
  13034. - add_interrupt_randomness(irq, flags);
  13035. +#ifndef CONFIG_PREEMPT_RT_FULL
  13036. + add_interrupt_randomness(irq, flags, ip);
  13037. +#else
  13038. + desc->random_ip = ip;
  13039. +#endif
  13040. if (!noirqdebug)
  13041. note_interrupt(irq, desc, retval);
  13042. diff -Nur linux-4.1.6.orig/kernel/irq/manage.c linux-4.1.6/kernel/irq/manage.c
  13043. --- linux-4.1.6.orig/kernel/irq/manage.c 2015-08-17 05:52:51.000000000 +0200
  13044. +++ linux-4.1.6/kernel/irq/manage.c 2015-09-08 23:49:08.093868717 +0200
  13045. @@ -22,6 +22,7 @@
  13046. #include "internals.h"
  13047. #ifdef CONFIG_IRQ_FORCED_THREADING
  13048. +# ifndef CONFIG_PREEMPT_RT_BASE
  13049. __read_mostly bool force_irqthreads;
  13050. static int __init setup_forced_irqthreads(char *arg)
  13051. @@ -30,6 +31,7 @@
  13052. return 0;
  13053. }
  13054. early_param("threadirqs", setup_forced_irqthreads);
  13055. +# endif
  13056. #endif
  13057. static void __synchronize_hardirq(struct irq_desc *desc)
  13058. @@ -179,6 +181,62 @@
  13059. irq_get_pending(struct cpumask *mask, struct irq_desc *desc) { }
  13060. #endif
  13061. +#ifdef CONFIG_PREEMPT_RT_FULL
  13062. +static void _irq_affinity_notify(struct irq_affinity_notify *notify);
  13063. +static struct task_struct *set_affinity_helper;
  13064. +static LIST_HEAD(affinity_list);
  13065. +static DEFINE_RAW_SPINLOCK(affinity_list_lock);
  13066. +
  13067. +static int set_affinity_thread(void *unused)
  13068. +{
  13069. + while (1) {
  13070. + struct irq_affinity_notify *notify;
  13071. + int empty;
  13072. +
  13073. + set_current_state(TASK_INTERRUPTIBLE);
  13074. +
  13075. + raw_spin_lock_irq(&affinity_list_lock);
  13076. + empty = list_empty(&affinity_list);
  13077. + raw_spin_unlock_irq(&affinity_list_lock);
  13078. +
  13079. + if (empty)
  13080. + schedule();
  13081. + if (kthread_should_stop())
  13082. + break;
  13083. + set_current_state(TASK_RUNNING);
  13084. +try_next:
  13085. + notify = NULL;
  13086. +
  13087. + raw_spin_lock_irq(&affinity_list_lock);
  13088. + if (!list_empty(&affinity_list)) {
  13089. + notify = list_first_entry(&affinity_list,
  13090. + struct irq_affinity_notify, list);
  13091. + list_del_init(&notify->list);
  13092. + }
  13093. + raw_spin_unlock_irq(&affinity_list_lock);
  13094. +
  13095. + if (!notify)
  13096. + continue;
  13097. + _irq_affinity_notify(notify);
  13098. + goto try_next;
  13099. + }
  13100. + return 0;
  13101. +}
  13102. +
  13103. +static void init_helper_thread(void)
  13104. +{
  13105. + if (set_affinity_helper)
  13106. + return;
  13107. + set_affinity_helper = kthread_run(set_affinity_thread, NULL,
  13108. + "affinity-cb");
  13109. + WARN_ON(IS_ERR(set_affinity_helper));
  13110. +}
  13111. +#else
  13112. +
  13113. +static inline void init_helper_thread(void) { }
  13114. +
  13115. +#endif
  13116. +
  13117. int irq_do_set_affinity(struct irq_data *data, const struct cpumask *mask,
  13118. bool force)
  13119. {
  13120. @@ -218,7 +276,17 @@
  13121. if (desc->affinity_notify) {
  13122. kref_get(&desc->affinity_notify->kref);
  13123. +
  13124. +#ifdef CONFIG_PREEMPT_RT_FULL
  13125. + raw_spin_lock(&affinity_list_lock);
  13126. + if (list_empty(&desc->affinity_notify->list))
  13127. + list_add_tail(&affinity_list,
  13128. + &desc->affinity_notify->list);
  13129. + raw_spin_unlock(&affinity_list_lock);
  13130. + wake_up_process(set_affinity_helper);
  13131. +#else
  13132. schedule_work(&desc->affinity_notify->work);
  13133. +#endif
  13134. }
  13135. irqd_set(data, IRQD_AFFINITY_SET);
  13136. @@ -256,10 +324,8 @@
  13137. }
  13138. EXPORT_SYMBOL_GPL(irq_set_affinity_hint);
  13139. -static void irq_affinity_notify(struct work_struct *work)
  13140. +static void _irq_affinity_notify(struct irq_affinity_notify *notify)
  13141. {
  13142. - struct irq_affinity_notify *notify =
  13143. - container_of(work, struct irq_affinity_notify, work);
  13144. struct irq_desc *desc = irq_to_desc(notify->irq);
  13145. cpumask_var_t cpumask;
  13146. unsigned long flags;
  13147. @@ -281,6 +347,13 @@
  13148. kref_put(&notify->kref, notify->release);
  13149. }
  13150. +static void irq_affinity_notify(struct work_struct *work)
  13151. +{
  13152. + struct irq_affinity_notify *notify =
  13153. + container_of(work, struct irq_affinity_notify, work);
  13154. + _irq_affinity_notify(notify);
  13155. +}
  13156. +
  13157. /**
  13158. * irq_set_affinity_notifier - control notification of IRQ affinity changes
  13159. * @irq: Interrupt for which to enable/disable notification
  13160. @@ -310,6 +383,8 @@
  13161. notify->irq = irq;
  13162. kref_init(&notify->kref);
  13163. INIT_WORK(&notify->work, irq_affinity_notify);
  13164. + INIT_LIST_HEAD(&notify->list);
  13165. + init_helper_thread();
  13166. }
  13167. raw_spin_lock_irqsave(&desc->lock, flags);
  13168. @@ -825,7 +900,15 @@
  13169. local_bh_disable();
  13170. ret = action->thread_fn(action->irq, action->dev_id);
  13171. irq_finalize_oneshot(desc, action);
  13172. - local_bh_enable();
  13173. + /*
  13174. + * Interrupts which have real time requirements can be set up
  13175. + * to avoid softirq processing in the thread handler. This is
  13176. + * safe as these interrupts do not raise soft interrupts.
  13177. + */
  13178. + if (irq_settings_no_softirq_call(desc))
  13179. + _local_bh_enable();
  13180. + else
  13181. + local_bh_enable();
  13182. return ret;
  13183. }
  13184. @@ -908,6 +991,12 @@
  13185. if (action_ret == IRQ_HANDLED)
  13186. atomic_inc(&desc->threads_handled);
  13187. +#ifdef CONFIG_PREEMPT_RT_FULL
  13188. + migrate_disable();
  13189. + add_interrupt_randomness(action->irq, 0,
  13190. + desc->random_ip ^ (unsigned long) action);
  13191. + migrate_enable();
  13192. +#endif
  13193. wake_threads_waitq(desc);
  13194. }
  13195. @@ -1221,6 +1310,9 @@
  13196. irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
  13197. }
  13198. + if (new->flags & IRQF_NO_SOFTIRQ_CALL)
  13199. + irq_settings_set_no_softirq_call(desc);
  13200. +
  13201. /* Set default affinity mask once everything is setup */
  13202. setup_affinity(irq, desc, mask);
  13203. diff -Nur linux-4.1.6.orig/kernel/irq/settings.h linux-4.1.6/kernel/irq/settings.h
  13204. --- linux-4.1.6.orig/kernel/irq/settings.h 2015-08-17 05:52:51.000000000 +0200
  13205. +++ linux-4.1.6/kernel/irq/settings.h 2015-09-08 23:49:08.093868717 +0200
  13206. @@ -15,6 +15,7 @@
  13207. _IRQ_NESTED_THREAD = IRQ_NESTED_THREAD,
  13208. _IRQ_PER_CPU_DEVID = IRQ_PER_CPU_DEVID,
  13209. _IRQ_IS_POLLED = IRQ_IS_POLLED,
  13210. + _IRQ_NO_SOFTIRQ_CALL = IRQ_NO_SOFTIRQ_CALL,
  13211. _IRQF_MODIFY_MASK = IRQF_MODIFY_MASK,
  13212. };
  13213. @@ -28,6 +29,7 @@
  13214. #define IRQ_NESTED_THREAD GOT_YOU_MORON
  13215. #define IRQ_PER_CPU_DEVID GOT_YOU_MORON
  13216. #define IRQ_IS_POLLED GOT_YOU_MORON
  13217. +#define IRQ_NO_SOFTIRQ_CALL GOT_YOU_MORON
  13218. #undef IRQF_MODIFY_MASK
  13219. #define IRQF_MODIFY_MASK GOT_YOU_MORON
  13220. @@ -38,6 +40,16 @@
  13221. desc->status_use_accessors |= (set & _IRQF_MODIFY_MASK);
  13222. }
  13223. +static inline bool irq_settings_no_softirq_call(struct irq_desc *desc)
  13224. +{
  13225. + return desc->status_use_accessors & _IRQ_NO_SOFTIRQ_CALL;
  13226. +}
  13227. +
  13228. +static inline void irq_settings_set_no_softirq_call(struct irq_desc *desc)
  13229. +{
  13230. + desc->status_use_accessors |= _IRQ_NO_SOFTIRQ_CALL;
  13231. +}
  13232. +
  13233. static inline bool irq_settings_is_per_cpu(struct irq_desc *desc)
  13234. {
  13235. return desc->status_use_accessors & _IRQ_PER_CPU;
  13236. diff -Nur linux-4.1.6.orig/kernel/irq/spurious.c linux-4.1.6/kernel/irq/spurious.c
  13237. --- linux-4.1.6.orig/kernel/irq/spurious.c 2015-08-17 05:52:51.000000000 +0200
  13238. +++ linux-4.1.6/kernel/irq/spurious.c 2015-09-08 23:49:08.093868717 +0200
  13239. @@ -444,6 +444,10 @@
  13240. static int __init irqfixup_setup(char *str)
  13241. {
  13242. +#ifdef CONFIG_PREEMPT_RT_BASE
  13243. + pr_warn("irqfixup boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  13244. + return 1;
  13245. +#endif
  13246. irqfixup = 1;
  13247. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  13248. printk(KERN_WARNING "This may impact system performance.\n");
  13249. @@ -456,6 +460,10 @@
  13250. static int __init irqpoll_setup(char *str)
  13251. {
  13252. +#ifdef CONFIG_PREEMPT_RT_BASE
  13253. + pr_warn("irqpoll boot option not supported w/ CONFIG_PREEMPT_RT_BASE\n");
  13254. + return 1;
  13255. +#endif
  13256. irqfixup = 2;
  13257. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  13258. "enabled\n");
  13259. diff -Nur linux-4.1.6.orig/kernel/irq_work.c linux-4.1.6/kernel/irq_work.c
  13260. --- linux-4.1.6.orig/kernel/irq_work.c 2015-08-17 05:52:51.000000000 +0200
  13261. +++ linux-4.1.6/kernel/irq_work.c 2015-09-08 23:49:08.101867828 +0200
  13262. @@ -17,6 +17,7 @@
  13263. #include <linux/cpu.h>
  13264. #include <linux/notifier.h>
  13265. #include <linux/smp.h>
  13266. +#include <linux/interrupt.h>
  13267. #include <asm/processor.h>
  13268. @@ -65,6 +66,8 @@
  13269. */
  13270. bool irq_work_queue_on(struct irq_work *work, int cpu)
  13271. {
  13272. + struct llist_head *list;
  13273. +
  13274. /* All work should have been flushed before going offline */
  13275. WARN_ON_ONCE(cpu_is_offline(cpu));
  13276. @@ -75,7 +78,12 @@
  13277. if (!irq_work_claim(work))
  13278. return false;
  13279. - if (llist_add(&work->llnode, &per_cpu(raised_list, cpu)))
  13280. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL) && !(work->flags & IRQ_WORK_HARD_IRQ))
  13281. + list = &per_cpu(lazy_list, cpu);
  13282. + else
  13283. + list = &per_cpu(raised_list, cpu);
  13284. +
  13285. + if (llist_add(&work->llnode, list))
  13286. arch_send_call_function_single_ipi(cpu);
  13287. return true;
  13288. @@ -86,6 +94,9 @@
  13289. /* Enqueue the irq work @work on the current CPU */
  13290. bool irq_work_queue(struct irq_work *work)
  13291. {
  13292. + struct llist_head *list;
  13293. + bool lazy_work, realtime = IS_ENABLED(CONFIG_PREEMPT_RT_FULL);
  13294. +
  13295. /* Only queue if not already pending */
  13296. if (!irq_work_claim(work))
  13297. return false;
  13298. @@ -93,13 +104,15 @@
  13299. /* Queue the entry and raise the IPI if needed. */
  13300. preempt_disable();
  13301. - /* If the work is "lazy", handle it from next tick if any */
  13302. - if (work->flags & IRQ_WORK_LAZY) {
  13303. - if (llist_add(&work->llnode, this_cpu_ptr(&lazy_list)) &&
  13304. - tick_nohz_tick_stopped())
  13305. - arch_irq_work_raise();
  13306. - } else {
  13307. - if (llist_add(&work->llnode, this_cpu_ptr(&raised_list)))
  13308. + lazy_work = work->flags & IRQ_WORK_LAZY;
  13309. +
  13310. + if (lazy_work || (realtime && !(work->flags & IRQ_WORK_HARD_IRQ)))
  13311. + list = this_cpu_ptr(&lazy_list);
  13312. + else
  13313. + list = this_cpu_ptr(&raised_list);
  13314. +
  13315. + if (llist_add(&work->llnode, list)) {
  13316. + if (!lazy_work || tick_nohz_tick_stopped())
  13317. arch_irq_work_raise();
  13318. }
  13319. @@ -116,9 +129,8 @@
  13320. raised = this_cpu_ptr(&raised_list);
  13321. lazy = this_cpu_ptr(&lazy_list);
  13322. - if (llist_empty(raised) || arch_irq_work_has_interrupt())
  13323. - if (llist_empty(lazy))
  13324. - return false;
  13325. + if (llist_empty(raised) && llist_empty(lazy))
  13326. + return false;
  13327. /* All work should have been flushed before going offline */
  13328. WARN_ON_ONCE(cpu_is_offline(smp_processor_id()));
  13329. @@ -132,7 +144,7 @@
  13330. struct irq_work *work;
  13331. struct llist_node *llnode;
  13332. - BUG_ON(!irqs_disabled());
  13333. + BUG_ON_NONRT(!irqs_disabled());
  13334. if (llist_empty(list))
  13335. return;
  13336. @@ -169,7 +181,16 @@
  13337. void irq_work_run(void)
  13338. {
  13339. irq_work_run_list(this_cpu_ptr(&raised_list));
  13340. - irq_work_run_list(this_cpu_ptr(&lazy_list));
  13341. + if (IS_ENABLED(CONFIG_PREEMPT_RT_FULL)) {
  13342. + /*
  13343. + * NOTE: we raise softirq via IPI for safety,
  13344. + * and execute in irq_work_tick() to move the
  13345. + * overhead from hard to soft irq context.
  13346. + */
  13347. + if (!llist_empty(this_cpu_ptr(&lazy_list)))
  13348. + raise_softirq(TIMER_SOFTIRQ);
  13349. + } else
  13350. + irq_work_run_list(this_cpu_ptr(&lazy_list));
  13351. }
  13352. EXPORT_SYMBOL_GPL(irq_work_run);
  13353. diff -Nur linux-4.1.6.orig/kernel/Kconfig.locks linux-4.1.6/kernel/Kconfig.locks
  13354. --- linux-4.1.6.orig/kernel/Kconfig.locks 2015-08-17 05:52:51.000000000 +0200
  13355. +++ linux-4.1.6/kernel/Kconfig.locks 2015-09-08 23:49:08.085869602 +0200
  13356. @@ -225,11 +225,11 @@
  13357. config MUTEX_SPIN_ON_OWNER
  13358. def_bool y
  13359. - depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW
  13360. + depends on SMP && !DEBUG_MUTEXES && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  13361. config RWSEM_SPIN_ON_OWNER
  13362. def_bool y
  13363. - depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW
  13364. + depends on SMP && RWSEM_XCHGADD_ALGORITHM && ARCH_SUPPORTS_ATOMIC_RMW && !PREEMPT_RT_FULL
  13365. config LOCK_SPIN_ON_OWNER
  13366. def_bool y
  13367. diff -Nur linux-4.1.6.orig/kernel/Kconfig.preempt linux-4.1.6/kernel/Kconfig.preempt
  13368. --- linux-4.1.6.orig/kernel/Kconfig.preempt 2015-08-17 05:52:51.000000000 +0200
  13369. +++ linux-4.1.6/kernel/Kconfig.preempt 2015-09-08 23:49:08.085869602 +0200
  13370. @@ -1,3 +1,16 @@
  13371. +config PREEMPT
  13372. + bool
  13373. + select PREEMPT_COUNT
  13374. +
  13375. +config PREEMPT_RT_BASE
  13376. + bool
  13377. + select PREEMPT
  13378. +
  13379. +config HAVE_PREEMPT_LAZY
  13380. + bool
  13381. +
  13382. +config PREEMPT_LAZY
  13383. + def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT_FULL
  13384. choice
  13385. prompt "Preemption Model"
  13386. @@ -33,9 +46,9 @@
  13387. Select this if you are building a kernel for a desktop system.
  13388. -config PREEMPT
  13389. +config PREEMPT__LL
  13390. bool "Preemptible Kernel (Low-Latency Desktop)"
  13391. - select PREEMPT_COUNT
  13392. + select PREEMPT
  13393. select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
  13394. help
  13395. This option reduces the latency of the kernel by making
  13396. @@ -52,6 +65,22 @@
  13397. embedded system with latency requirements in the milliseconds
  13398. range.
  13399. +config PREEMPT_RTB
  13400. + bool "Preemptible Kernel (Basic RT)"
  13401. + select PREEMPT_RT_BASE
  13402. + help
  13403. + This option is basically the same as (Low-Latency Desktop) but
  13404. + enables changes which are preliminary for the full preemptible
  13405. + RT kernel.
  13406. +
  13407. +config PREEMPT_RT_FULL
  13408. + bool "Fully Preemptible Kernel (RT)"
  13409. + depends on IRQ_FORCED_THREADING
  13410. + select PREEMPT_RT_BASE
  13411. + select PREEMPT_RCU
  13412. + help
  13413. + All and everything
  13414. +
  13415. endchoice
  13416. config PREEMPT_COUNT
  13417. diff -Nur linux-4.1.6.orig/kernel/ksysfs.c linux-4.1.6/kernel/ksysfs.c
  13418. --- linux-4.1.6.orig/kernel/ksysfs.c 2015-08-17 05:52:51.000000000 +0200
  13419. +++ linux-4.1.6/kernel/ksysfs.c 2015-09-08 23:49:08.101867828 +0200
  13420. @@ -136,6 +136,15 @@
  13421. #endif /* CONFIG_KEXEC */
  13422. +#if defined(CONFIG_PREEMPT_RT_FULL)
  13423. +static ssize_t realtime_show(struct kobject *kobj,
  13424. + struct kobj_attribute *attr, char *buf)
  13425. +{
  13426. + return sprintf(buf, "%d\n", 1);
  13427. +}
  13428. +KERNEL_ATTR_RO(realtime);
  13429. +#endif
  13430. +
  13431. /* whether file capabilities are enabled */
  13432. static ssize_t fscaps_show(struct kobject *kobj,
  13433. struct kobj_attribute *attr, char *buf)
  13434. @@ -203,6 +212,9 @@
  13435. &vmcoreinfo_attr.attr,
  13436. #endif
  13437. &rcu_expedited_attr.attr,
  13438. +#ifdef CONFIG_PREEMPT_RT_FULL
  13439. + &realtime_attr.attr,
  13440. +#endif
  13441. NULL
  13442. };
  13443. diff -Nur linux-4.1.6.orig/kernel/locking/lglock.c linux-4.1.6/kernel/locking/lglock.c
  13444. --- linux-4.1.6.orig/kernel/locking/lglock.c 2015-08-17 05:52:51.000000000 +0200
  13445. +++ linux-4.1.6/kernel/locking/lglock.c 2015-09-08 23:49:08.101867828 +0200
  13446. @@ -4,6 +4,15 @@
  13447. #include <linux/cpu.h>
  13448. #include <linux/string.h>
  13449. +#ifndef CONFIG_PREEMPT_RT_FULL
  13450. +# define lg_lock_ptr arch_spinlock_t
  13451. +# define lg_do_lock(l) arch_spin_lock(l)
  13452. +# define lg_do_unlock(l) arch_spin_unlock(l)
  13453. +#else
  13454. +# define lg_lock_ptr struct rt_mutex
  13455. +# define lg_do_lock(l) __rt_spin_lock(l)
  13456. +# define lg_do_unlock(l) __rt_spin_unlock(l)
  13457. +#endif
  13458. /*
  13459. * Note there is no uninit, so lglocks cannot be defined in
  13460. * modules (but it's fine to use them from there)
  13461. @@ -12,51 +21,60 @@
  13462. void lg_lock_init(struct lglock *lg, char *name)
  13463. {
  13464. +#ifdef CONFIG_PREEMPT_RT_FULL
  13465. + int i;
  13466. +
  13467. + for_each_possible_cpu(i) {
  13468. + struct rt_mutex *lock = per_cpu_ptr(lg->lock, i);
  13469. +
  13470. + rt_mutex_init(lock);
  13471. + }
  13472. +#endif
  13473. LOCKDEP_INIT_MAP(&lg->lock_dep_map, name, &lg->lock_key, 0);
  13474. }
  13475. EXPORT_SYMBOL(lg_lock_init);
  13476. void lg_local_lock(struct lglock *lg)
  13477. {
  13478. - arch_spinlock_t *lock;
  13479. + lg_lock_ptr *lock;
  13480. - preempt_disable();
  13481. + migrate_disable();
  13482. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  13483. lock = this_cpu_ptr(lg->lock);
  13484. - arch_spin_lock(lock);
  13485. + lg_do_lock(lock);
  13486. }
  13487. EXPORT_SYMBOL(lg_local_lock);
  13488. void lg_local_unlock(struct lglock *lg)
  13489. {
  13490. - arch_spinlock_t *lock;
  13491. + lg_lock_ptr *lock;
  13492. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  13493. lock = this_cpu_ptr(lg->lock);
  13494. - arch_spin_unlock(lock);
  13495. - preempt_enable();
  13496. + lg_do_unlock(lock);
  13497. + migrate_enable();
  13498. }
  13499. EXPORT_SYMBOL(lg_local_unlock);
  13500. void lg_local_lock_cpu(struct lglock *lg, int cpu)
  13501. {
  13502. - arch_spinlock_t *lock;
  13503. + lg_lock_ptr *lock;
  13504. - preempt_disable();
  13505. + preempt_disable_nort();
  13506. lock_acquire_shared(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  13507. lock = per_cpu_ptr(lg->lock, cpu);
  13508. - arch_spin_lock(lock);
  13509. + lg_do_lock(lock);
  13510. }
  13511. EXPORT_SYMBOL(lg_local_lock_cpu);
  13512. void lg_local_unlock_cpu(struct lglock *lg, int cpu)
  13513. {
  13514. - arch_spinlock_t *lock;
  13515. + lg_lock_ptr *lock;
  13516. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  13517. lock = per_cpu_ptr(lg->lock, cpu);
  13518. - arch_spin_unlock(lock);
  13519. - preempt_enable();
  13520. + lg_do_unlock(lock);
  13521. + preempt_enable_nort();
  13522. }
  13523. EXPORT_SYMBOL(lg_local_unlock_cpu);
  13524. @@ -64,12 +82,12 @@
  13525. {
  13526. int i;
  13527. - preempt_disable();
  13528. + preempt_disable_nort();
  13529. lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  13530. for_each_possible_cpu(i) {
  13531. - arch_spinlock_t *lock;
  13532. + lg_lock_ptr *lock;
  13533. lock = per_cpu_ptr(lg->lock, i);
  13534. - arch_spin_lock(lock);
  13535. + lg_do_lock(lock);
  13536. }
  13537. }
  13538. EXPORT_SYMBOL(lg_global_lock);
  13539. @@ -80,10 +98,35 @@
  13540. lock_release(&lg->lock_dep_map, 1, _RET_IP_);
  13541. for_each_possible_cpu(i) {
  13542. - arch_spinlock_t *lock;
  13543. + lg_lock_ptr *lock;
  13544. lock = per_cpu_ptr(lg->lock, i);
  13545. - arch_spin_unlock(lock);
  13546. + lg_do_unlock(lock);
  13547. }
  13548. - preempt_enable();
  13549. + preempt_enable_nort();
  13550. }
  13551. EXPORT_SYMBOL(lg_global_unlock);
  13552. +
  13553. +#ifdef CONFIG_PREEMPT_RT_FULL
  13554. +/*
  13555. + * HACK: If you use this, you get to keep the pieces.
  13556. + * Used in queue_stop_cpus_work() when stop machinery
  13557. + * is called from inactive CPU, so we can't schedule.
  13558. + */
  13559. +# define lg_do_trylock_relax(l) \
  13560. + do { \
  13561. + while (!__rt_spin_trylock(l)) \
  13562. + cpu_relax(); \
  13563. + } while (0)
  13564. +
  13565. +void lg_global_trylock_relax(struct lglock *lg)
  13566. +{
  13567. + int i;
  13568. +
  13569. + lock_acquire_exclusive(&lg->lock_dep_map, 0, 0, NULL, _RET_IP_);
  13570. + for_each_possible_cpu(i) {
  13571. + lg_lock_ptr *lock;
  13572. + lock = per_cpu_ptr(lg->lock, i);
  13573. + lg_do_trylock_relax(lock);
  13574. + }
  13575. +}
  13576. +#endif
  13577. diff -Nur linux-4.1.6.orig/kernel/locking/lockdep.c linux-4.1.6/kernel/locking/lockdep.c
  13578. --- linux-4.1.6.orig/kernel/locking/lockdep.c 2015-08-17 05:52:51.000000000 +0200
  13579. +++ linux-4.1.6/kernel/locking/lockdep.c 2015-09-08 23:49:08.101867828 +0200
  13580. @@ -3563,6 +3563,7 @@
  13581. }
  13582. }
  13583. +#ifndef CONFIG_PREEMPT_RT_FULL
  13584. /*
  13585. * We dont accurately track softirq state in e.g.
  13586. * hardirq contexts (such as on 4KSTACKS), so only
  13587. @@ -3577,6 +3578,7 @@
  13588. DEBUG_LOCKS_WARN_ON(!current->softirqs_enabled);
  13589. }
  13590. }
  13591. +#endif
  13592. if (!debug_locks)
  13593. print_irqtrace_events(current);
  13594. diff -Nur linux-4.1.6.orig/kernel/locking/locktorture.c linux-4.1.6/kernel/locking/locktorture.c
  13595. --- linux-4.1.6.orig/kernel/locking/locktorture.c 2015-08-17 05:52:51.000000000 +0200
  13596. +++ linux-4.1.6/kernel/locking/locktorture.c 2015-09-08 23:49:08.101867828 +0200
  13597. @@ -24,7 +24,6 @@
  13598. #include <linux/module.h>
  13599. #include <linux/kthread.h>
  13600. #include <linux/spinlock.h>
  13601. -#include <linux/rwlock.h>
  13602. #include <linux/mutex.h>
  13603. #include <linux/rwsem.h>
  13604. #include <linux/smp.h>
  13605. diff -Nur linux-4.1.6.orig/kernel/locking/Makefile linux-4.1.6/kernel/locking/Makefile
  13606. --- linux-4.1.6.orig/kernel/locking/Makefile 2015-08-17 05:52:51.000000000 +0200
  13607. +++ linux-4.1.6/kernel/locking/Makefile 2015-09-08 23:49:08.101867828 +0200
  13608. @@ -1,5 +1,5 @@
  13609. -obj-y += mutex.o semaphore.o rwsem.o
  13610. +obj-y += semaphore.o
  13611. ifdef CONFIG_FUNCTION_TRACER
  13612. CFLAGS_REMOVE_lockdep.o = $(CC_FLAGS_FTRACE)
  13613. @@ -8,7 +8,11 @@
  13614. CFLAGS_REMOVE_rtmutex-debug.o = $(CC_FLAGS_FTRACE)
  13615. endif
  13616. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  13617. +obj-y += mutex.o
  13618. obj-$(CONFIG_DEBUG_MUTEXES) += mutex-debug.o
  13619. +obj-y += rwsem.o
  13620. +endif
  13621. obj-$(CONFIG_LOCKDEP) += lockdep.o
  13622. ifeq ($(CONFIG_PROC_FS),y)
  13623. obj-$(CONFIG_LOCKDEP) += lockdep_proc.o
  13624. @@ -22,8 +26,11 @@
  13625. obj-$(CONFIG_RT_MUTEX_TESTER) += rtmutex-tester.o
  13626. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock.o
  13627. obj-$(CONFIG_DEBUG_SPINLOCK) += spinlock_debug.o
  13628. +ifneq ($(CONFIG_PREEMPT_RT_FULL),y)
  13629. obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
  13630. obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o
  13631. +endif
  13632. obj-$(CONFIG_PERCPU_RWSEM) += percpu-rwsem.o
  13633. +obj-$(CONFIG_PREEMPT_RT_FULL) += rt.o
  13634. obj-$(CONFIG_QUEUE_RWLOCK) += qrwlock.o
  13635. obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o
  13636. diff -Nur linux-4.1.6.orig/kernel/locking/rt.c linux-4.1.6/kernel/locking/rt.c
  13637. --- linux-4.1.6.orig/kernel/locking/rt.c 1970-01-01 01:00:00.000000000 +0100
  13638. +++ linux-4.1.6/kernel/locking/rt.c 2015-09-08 23:49:08.101867828 +0200
  13639. @@ -0,0 +1,461 @@
  13640. +/*
  13641. + * kernel/rt.c
  13642. + *
  13643. + * Real-Time Preemption Support
  13644. + *
  13645. + * started by Ingo Molnar:
  13646. + *
  13647. + * Copyright (C) 2004-2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  13648. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  13649. + *
  13650. + * historic credit for proving that Linux spinlocks can be implemented via
  13651. + * RT-aware mutexes goes to many people: The Pmutex project (Dirk Grambow
  13652. + * and others) who prototyped it on 2.4 and did lots of comparative
  13653. + * research and analysis; TimeSys, for proving that you can implement a
  13654. + * fully preemptible kernel via the use of IRQ threading and mutexes;
  13655. + * Bill Huey for persuasively arguing on lkml that the mutex model is the
  13656. + * right one; and to MontaVista, who ported pmutexes to 2.6.
  13657. + *
  13658. + * This code is a from-scratch implementation and is not based on pmutexes,
  13659. + * but the idea of converting spinlocks to mutexes is used here too.
  13660. + *
  13661. + * lock debugging, locking tree, deadlock detection:
  13662. + *
  13663. + * Copyright (C) 2004, LynuxWorks, Inc., Igor Manyilov, Bill Huey
  13664. + * Released under the General Public License (GPL).
  13665. + *
  13666. + * Includes portions of the generic R/W semaphore implementation from:
  13667. + *
  13668. + * Copyright (c) 2001 David Howells (dhowells@redhat.com).
  13669. + * - Derived partially from idea by Andrea Arcangeli <andrea@suse.de>
  13670. + * - Derived also from comments by Linus
  13671. + *
  13672. + * Pending ownership of locks and ownership stealing:
  13673. + *
  13674. + * Copyright (C) 2005, Kihon Technologies Inc., Steven Rostedt
  13675. + *
  13676. + * (also by Steven Rostedt)
  13677. + * - Converted single pi_lock to individual task locks.
  13678. + *
  13679. + * By Esben Nielsen:
  13680. + * Doing priority inheritance with help of the scheduler.
  13681. + *
  13682. + * Copyright (C) 2006, Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  13683. + * - major rework based on Esben Nielsens initial patch
  13684. + * - replaced thread_info references by task_struct refs
  13685. + * - removed task->pending_owner dependency
  13686. + * - BKL drop/reacquire for semaphore style locks to avoid deadlocks
  13687. + * in the scheduler return path as discussed with Steven Rostedt
  13688. + *
  13689. + * Copyright (C) 2006, Kihon Technologies Inc.
  13690. + * Steven Rostedt <rostedt@goodmis.org>
  13691. + * - debugged and patched Thomas Gleixner's rework.
  13692. + * - added back the cmpxchg to the rework.
  13693. + * - turned atomic require back on for SMP.
  13694. + */
  13695. +
  13696. +#include <linux/spinlock.h>
  13697. +#include <linux/rtmutex.h>
  13698. +#include <linux/sched.h>
  13699. +#include <linux/delay.h>
  13700. +#include <linux/module.h>
  13701. +#include <linux/kallsyms.h>
  13702. +#include <linux/syscalls.h>
  13703. +#include <linux/interrupt.h>
  13704. +#include <linux/plist.h>
  13705. +#include <linux/fs.h>
  13706. +#include <linux/futex.h>
  13707. +#include <linux/hrtimer.h>
  13708. +
  13709. +#include "rtmutex_common.h"
  13710. +
  13711. +/*
  13712. + * struct mutex functions
  13713. + */
  13714. +void __mutex_do_init(struct mutex *mutex, const char *name,
  13715. + struct lock_class_key *key)
  13716. +{
  13717. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13718. + /*
  13719. + * Make sure we are not reinitializing a held lock:
  13720. + */
  13721. + debug_check_no_locks_freed((void *)mutex, sizeof(*mutex));
  13722. + lockdep_init_map(&mutex->dep_map, name, key, 0);
  13723. +#endif
  13724. + mutex->lock.save_state = 0;
  13725. +}
  13726. +EXPORT_SYMBOL(__mutex_do_init);
  13727. +
  13728. +void __lockfunc _mutex_lock(struct mutex *lock)
  13729. +{
  13730. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  13731. + rt_mutex_lock(&lock->lock);
  13732. +}
  13733. +EXPORT_SYMBOL(_mutex_lock);
  13734. +
  13735. +int __lockfunc _mutex_lock_interruptible(struct mutex *lock)
  13736. +{
  13737. + int ret;
  13738. +
  13739. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  13740. + ret = rt_mutex_lock_interruptible(&lock->lock);
  13741. + if (ret)
  13742. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  13743. + return ret;
  13744. +}
  13745. +EXPORT_SYMBOL(_mutex_lock_interruptible);
  13746. +
  13747. +int __lockfunc _mutex_lock_killable(struct mutex *lock)
  13748. +{
  13749. + int ret;
  13750. +
  13751. + mutex_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  13752. + ret = rt_mutex_lock_killable(&lock->lock);
  13753. + if (ret)
  13754. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  13755. + return ret;
  13756. +}
  13757. +EXPORT_SYMBOL(_mutex_lock_killable);
  13758. +
  13759. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13760. +void __lockfunc _mutex_lock_nested(struct mutex *lock, int subclass)
  13761. +{
  13762. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  13763. + rt_mutex_lock(&lock->lock);
  13764. +}
  13765. +EXPORT_SYMBOL(_mutex_lock_nested);
  13766. +
  13767. +void __lockfunc _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest)
  13768. +{
  13769. + mutex_acquire_nest(&lock->dep_map, 0, 0, nest, _RET_IP_);
  13770. + rt_mutex_lock(&lock->lock);
  13771. +}
  13772. +EXPORT_SYMBOL(_mutex_lock_nest_lock);
  13773. +
  13774. +int __lockfunc _mutex_lock_interruptible_nested(struct mutex *lock, int subclass)
  13775. +{
  13776. + int ret;
  13777. +
  13778. + mutex_acquire_nest(&lock->dep_map, subclass, 0, NULL, _RET_IP_);
  13779. + ret = rt_mutex_lock_interruptible(&lock->lock);
  13780. + if (ret)
  13781. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  13782. + return ret;
  13783. +}
  13784. +EXPORT_SYMBOL(_mutex_lock_interruptible_nested);
  13785. +
  13786. +int __lockfunc _mutex_lock_killable_nested(struct mutex *lock, int subclass)
  13787. +{
  13788. + int ret;
  13789. +
  13790. + mutex_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  13791. + ret = rt_mutex_lock_killable(&lock->lock);
  13792. + if (ret)
  13793. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  13794. + return ret;
  13795. +}
  13796. +EXPORT_SYMBOL(_mutex_lock_killable_nested);
  13797. +#endif
  13798. +
  13799. +int __lockfunc _mutex_trylock(struct mutex *lock)
  13800. +{
  13801. + int ret = rt_mutex_trylock(&lock->lock);
  13802. +
  13803. + if (ret)
  13804. + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  13805. +
  13806. + return ret;
  13807. +}
  13808. +EXPORT_SYMBOL(_mutex_trylock);
  13809. +
  13810. +void __lockfunc _mutex_unlock(struct mutex *lock)
  13811. +{
  13812. + mutex_release(&lock->dep_map, 1, _RET_IP_);
  13813. + rt_mutex_unlock(&lock->lock);
  13814. +}
  13815. +EXPORT_SYMBOL(_mutex_unlock);
  13816. +
  13817. +/*
  13818. + * rwlock_t functions
  13819. + */
  13820. +int __lockfunc rt_write_trylock(rwlock_t *rwlock)
  13821. +{
  13822. + int ret;
  13823. +
  13824. + migrate_disable();
  13825. + ret = rt_mutex_trylock(&rwlock->lock);
  13826. + if (ret)
  13827. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  13828. + else
  13829. + migrate_enable();
  13830. +
  13831. + return ret;
  13832. +}
  13833. +EXPORT_SYMBOL(rt_write_trylock);
  13834. +
  13835. +int __lockfunc rt_write_trylock_irqsave(rwlock_t *rwlock, unsigned long *flags)
  13836. +{
  13837. + int ret;
  13838. +
  13839. + *flags = 0;
  13840. + ret = rt_write_trylock(rwlock);
  13841. + return ret;
  13842. +}
  13843. +EXPORT_SYMBOL(rt_write_trylock_irqsave);
  13844. +
  13845. +int __lockfunc rt_read_trylock(rwlock_t *rwlock)
  13846. +{
  13847. + struct rt_mutex *lock = &rwlock->lock;
  13848. + int ret = 1;
  13849. +
  13850. + /*
  13851. + * recursive read locks succeed when current owns the lock,
  13852. + * but not when read_depth == 0 which means that the lock is
  13853. + * write locked.
  13854. + */
  13855. + if (rt_mutex_owner(lock) != current) {
  13856. + migrate_disable();
  13857. + ret = rt_mutex_trylock(lock);
  13858. + if (ret)
  13859. + rwlock_acquire(&rwlock->dep_map, 0, 1, _RET_IP_);
  13860. + else
  13861. + migrate_enable();
  13862. +
  13863. + } else if (!rwlock->read_depth) {
  13864. + ret = 0;
  13865. + }
  13866. +
  13867. + if (ret)
  13868. + rwlock->read_depth++;
  13869. +
  13870. + return ret;
  13871. +}
  13872. +EXPORT_SYMBOL(rt_read_trylock);
  13873. +
  13874. +void __lockfunc rt_write_lock(rwlock_t *rwlock)
  13875. +{
  13876. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  13877. + migrate_disable();
  13878. + __rt_spin_lock(&rwlock->lock);
  13879. +}
  13880. +EXPORT_SYMBOL(rt_write_lock);
  13881. +
  13882. +void __lockfunc rt_read_lock(rwlock_t *rwlock)
  13883. +{
  13884. + struct rt_mutex *lock = &rwlock->lock;
  13885. +
  13886. +
  13887. + /*
  13888. + * recursive read locks succeed when current owns the lock
  13889. + */
  13890. + if (rt_mutex_owner(lock) != current) {
  13891. + migrate_disable();
  13892. + rwlock_acquire(&rwlock->dep_map, 0, 0, _RET_IP_);
  13893. + __rt_spin_lock(lock);
  13894. + }
  13895. + rwlock->read_depth++;
  13896. +}
  13897. +
  13898. +EXPORT_SYMBOL(rt_read_lock);
  13899. +
  13900. +void __lockfunc rt_write_unlock(rwlock_t *rwlock)
  13901. +{
  13902. + /* NOTE: we always pass in '1' for nested, for simplicity */
  13903. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  13904. + __rt_spin_unlock(&rwlock->lock);
  13905. + migrate_enable();
  13906. +}
  13907. +EXPORT_SYMBOL(rt_write_unlock);
  13908. +
  13909. +void __lockfunc rt_read_unlock(rwlock_t *rwlock)
  13910. +{
  13911. + /* Release the lock only when read_depth is down to 0 */
  13912. + if (--rwlock->read_depth == 0) {
  13913. + rwlock_release(&rwlock->dep_map, 1, _RET_IP_);
  13914. + __rt_spin_unlock(&rwlock->lock);
  13915. + migrate_enable();
  13916. + }
  13917. +}
  13918. +EXPORT_SYMBOL(rt_read_unlock);
  13919. +
  13920. +unsigned long __lockfunc rt_write_lock_irqsave(rwlock_t *rwlock)
  13921. +{
  13922. + rt_write_lock(rwlock);
  13923. +
  13924. + return 0;
  13925. +}
  13926. +EXPORT_SYMBOL(rt_write_lock_irqsave);
  13927. +
  13928. +unsigned long __lockfunc rt_read_lock_irqsave(rwlock_t *rwlock)
  13929. +{
  13930. + rt_read_lock(rwlock);
  13931. +
  13932. + return 0;
  13933. +}
  13934. +EXPORT_SYMBOL(rt_read_lock_irqsave);
  13935. +
  13936. +void __rt_rwlock_init(rwlock_t *rwlock, char *name, struct lock_class_key *key)
  13937. +{
  13938. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  13939. + /*
  13940. + * Make sure we are not reinitializing a held lock:
  13941. + */
  13942. + debug_check_no_locks_freed((void *)rwlock, sizeof(*rwlock));
  13943. + lockdep_init_map(&rwlock->dep_map, name, key, 0);
  13944. +#endif
  13945. + rwlock->lock.save_state = 1;
  13946. + rwlock->read_depth = 0;
  13947. +}
  13948. +EXPORT_SYMBOL(__rt_rwlock_init);
  13949. +
  13950. +/*
  13951. + * rw_semaphores
  13952. + */
  13953. +
  13954. +void rt_up_write(struct rw_semaphore *rwsem)
  13955. +{
  13956. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  13957. + rt_mutex_unlock(&rwsem->lock);
  13958. +}
  13959. +EXPORT_SYMBOL(rt_up_write);
  13960. +
  13961. +void __rt_up_read(struct rw_semaphore *rwsem)
  13962. +{
  13963. + if (--rwsem->read_depth == 0)
  13964. + rt_mutex_unlock(&rwsem->lock);
  13965. +}
  13966. +
  13967. +void rt_up_read(struct rw_semaphore *rwsem)
  13968. +{
  13969. + rwsem_release(&rwsem->dep_map, 1, _RET_IP_);
  13970. + __rt_up_read(rwsem);
  13971. +}
  13972. +EXPORT_SYMBOL(rt_up_read);
  13973. +
  13974. +/*
  13975. + * downgrade a write lock into a read lock
  13976. + * - just wake up any readers at the front of the queue
  13977. + */
  13978. +void rt_downgrade_write(struct rw_semaphore *rwsem)
  13979. +{
  13980. + BUG_ON(rt_mutex_owner(&rwsem->lock) != current);
  13981. + rwsem->read_depth = 1;
  13982. +}
  13983. +EXPORT_SYMBOL(rt_downgrade_write);
  13984. +
  13985. +int rt_down_write_trylock(struct rw_semaphore *rwsem)
  13986. +{
  13987. + int ret = rt_mutex_trylock(&rwsem->lock);
  13988. +
  13989. + if (ret)
  13990. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  13991. + return ret;
  13992. +}
  13993. +EXPORT_SYMBOL(rt_down_write_trylock);
  13994. +
  13995. +void rt_down_write(struct rw_semaphore *rwsem)
  13996. +{
  13997. + rwsem_acquire(&rwsem->dep_map, 0, 0, _RET_IP_);
  13998. + rt_mutex_lock(&rwsem->lock);
  13999. +}
  14000. +EXPORT_SYMBOL(rt_down_write);
  14001. +
  14002. +void rt_down_write_nested(struct rw_semaphore *rwsem, int subclass)
  14003. +{
  14004. + rwsem_acquire(&rwsem->dep_map, subclass, 0, _RET_IP_);
  14005. + rt_mutex_lock(&rwsem->lock);
  14006. +}
  14007. +EXPORT_SYMBOL(rt_down_write_nested);
  14008. +
  14009. +void rt_down_write_nested_lock(struct rw_semaphore *rwsem,
  14010. + struct lockdep_map *nest)
  14011. +{
  14012. + rwsem_acquire_nest(&rwsem->dep_map, 0, 0, nest, _RET_IP_);
  14013. + rt_mutex_lock(&rwsem->lock);
  14014. +}
  14015. +EXPORT_SYMBOL(rt_down_write_nested_lock);
  14016. +
  14017. +int rt_down_read_trylock(struct rw_semaphore *rwsem)
  14018. +{
  14019. + struct rt_mutex *lock = &rwsem->lock;
  14020. + int ret = 1;
  14021. +
  14022. + /*
  14023. + * recursive read locks succeed when current owns the rwsem,
  14024. + * but not when read_depth == 0 which means that the rwsem is
  14025. + * write locked.
  14026. + */
  14027. + if (rt_mutex_owner(lock) != current)
  14028. + ret = rt_mutex_trylock(&rwsem->lock);
  14029. + else if (!rwsem->read_depth)
  14030. + ret = 0;
  14031. +
  14032. + if (ret) {
  14033. + rwsem->read_depth++;
  14034. + rwsem_acquire(&rwsem->dep_map, 0, 1, _RET_IP_);
  14035. + }
  14036. + return ret;
  14037. +}
  14038. +EXPORT_SYMBOL(rt_down_read_trylock);
  14039. +
  14040. +static void __rt_down_read(struct rw_semaphore *rwsem, int subclass)
  14041. +{
  14042. + struct rt_mutex *lock = &rwsem->lock;
  14043. +
  14044. + rwsem_acquire_read(&rwsem->dep_map, subclass, 0, _RET_IP_);
  14045. +
  14046. + if (rt_mutex_owner(lock) != current)
  14047. + rt_mutex_lock(&rwsem->lock);
  14048. + rwsem->read_depth++;
  14049. +}
  14050. +
  14051. +void rt_down_read(struct rw_semaphore *rwsem)
  14052. +{
  14053. + __rt_down_read(rwsem, 0);
  14054. +}
  14055. +EXPORT_SYMBOL(rt_down_read);
  14056. +
  14057. +void rt_down_read_nested(struct rw_semaphore *rwsem, int subclass)
  14058. +{
  14059. + __rt_down_read(rwsem, subclass);
  14060. +}
  14061. +EXPORT_SYMBOL(rt_down_read_nested);
  14062. +
  14063. +void __rt_rwsem_init(struct rw_semaphore *rwsem, const char *name,
  14064. + struct lock_class_key *key)
  14065. +{
  14066. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  14067. + /*
  14068. + * Make sure we are not reinitializing a held lock:
  14069. + */
  14070. + debug_check_no_locks_freed((void *)rwsem, sizeof(*rwsem));
  14071. + lockdep_init_map(&rwsem->dep_map, name, key, 0);
  14072. +#endif
  14073. + rwsem->read_depth = 0;
  14074. + rwsem->lock.save_state = 0;
  14075. +}
  14076. +EXPORT_SYMBOL(__rt_rwsem_init);
  14077. +
  14078. +/**
  14079. + * atomic_dec_and_mutex_lock - return holding mutex if we dec to 0
  14080. + * @cnt: the atomic which we are to dec
  14081. + * @lock: the mutex to return holding if we dec to 0
  14082. + *
  14083. + * return true and hold lock if we dec to 0, return false otherwise
  14084. + */
  14085. +int atomic_dec_and_mutex_lock(atomic_t *cnt, struct mutex *lock)
  14086. +{
  14087. + /* dec if we can't possibly hit 0 */
  14088. + if (atomic_add_unless(cnt, -1, 1))
  14089. + return 0;
  14090. + /* we might hit 0, so take the lock */
  14091. + mutex_lock(lock);
  14092. + if (!atomic_dec_and_test(cnt)) {
  14093. + /* when we actually did the dec, we didn't hit 0 */
  14094. + mutex_unlock(lock);
  14095. + return 0;
  14096. + }
  14097. + /* we hit 0, and we hold the lock */
  14098. + return 1;
  14099. +}
  14100. +EXPORT_SYMBOL(atomic_dec_and_mutex_lock);
  14101. diff -Nur linux-4.1.6.orig/kernel/locking/rtmutex.c linux-4.1.6/kernel/locking/rtmutex.c
  14102. --- linux-4.1.6.orig/kernel/locking/rtmutex.c 2015-08-17 05:52:51.000000000 +0200
  14103. +++ linux-4.1.6/kernel/locking/rtmutex.c 2015-09-08 23:49:08.101867828 +0200
  14104. @@ -7,6 +7,11 @@
  14105. * Copyright (C) 2005-2006 Timesys Corp., Thomas Gleixner <tglx@timesys.com>
  14106. * Copyright (C) 2005 Kihon Technologies Inc., Steven Rostedt
  14107. * Copyright (C) 2006 Esben Nielsen
  14108. + * Adaptive Spinlocks:
  14109. + * Copyright (C) 2008 Novell, Inc., Gregory Haskins, Sven Dietrich,
  14110. + * and Peter Morreale,
  14111. + * Adaptive Spinlocks simplification:
  14112. + * Copyright (C) 2008 Red Hat, Inc., Steven Rostedt <srostedt@redhat.com>
  14113. *
  14114. * See Documentation/locking/rt-mutex-design.txt for details.
  14115. */
  14116. @@ -16,6 +21,7 @@
  14117. #include <linux/sched/rt.h>
  14118. #include <linux/sched/deadline.h>
  14119. #include <linux/timer.h>
  14120. +#include <linux/ww_mutex.h>
  14121. #include "rtmutex_common.h"
  14122. @@ -69,6 +75,12 @@
  14123. clear_rt_mutex_waiters(lock);
  14124. }
  14125. +static int rt_mutex_real_waiter(struct rt_mutex_waiter *waiter)
  14126. +{
  14127. + return waiter && waiter != PI_WAKEUP_INPROGRESS &&
  14128. + waiter != PI_REQUEUE_INPROGRESS;
  14129. +}
  14130. +
  14131. /*
  14132. * We can speed up the acquire/release, if the architecture
  14133. * supports cmpxchg and if there's no debugging state to be set up
  14134. @@ -300,7 +312,7 @@
  14135. * of task. We do not use the spin_xx_mutex() variants here as we are
  14136. * outside of the debug path.)
  14137. */
  14138. -static void rt_mutex_adjust_prio(struct task_struct *task)
  14139. +void rt_mutex_adjust_prio(struct task_struct *task)
  14140. {
  14141. unsigned long flags;
  14142. @@ -335,6 +347,14 @@
  14143. return debug_rt_mutex_detect_deadlock(waiter, chwalk);
  14144. }
  14145. +static void rt_mutex_wake_waiter(struct rt_mutex_waiter *waiter)
  14146. +{
  14147. + if (waiter->savestate)
  14148. + wake_up_lock_sleeper(waiter->task);
  14149. + else
  14150. + wake_up_process(waiter->task);
  14151. +}
  14152. +
  14153. /*
  14154. * Max number of times we'll walk the boosting chain:
  14155. */
  14156. @@ -342,7 +362,8 @@
  14157. static inline struct rt_mutex *task_blocked_on_lock(struct task_struct *p)
  14158. {
  14159. - return p->pi_blocked_on ? p->pi_blocked_on->lock : NULL;
  14160. + return rt_mutex_real_waiter(p->pi_blocked_on) ?
  14161. + p->pi_blocked_on->lock : NULL;
  14162. }
  14163. /*
  14164. @@ -479,7 +500,7 @@
  14165. * reached or the state of the chain has changed while we
  14166. * dropped the locks.
  14167. */
  14168. - if (!waiter)
  14169. + if (!rt_mutex_real_waiter(waiter))
  14170. goto out_unlock_pi;
  14171. /*
  14172. @@ -641,13 +662,16 @@
  14173. * follow here. This is the end of the chain we are walking.
  14174. */
  14175. if (!rt_mutex_owner(lock)) {
  14176. + struct rt_mutex_waiter *lock_top_waiter;
  14177. +
  14178. /*
  14179. * If the requeue [7] above changed the top waiter,
  14180. * then we need to wake the new top waiter up to try
  14181. * to get the lock.
  14182. */
  14183. - if (prerequeue_top_waiter != rt_mutex_top_waiter(lock))
  14184. - wake_up_process(rt_mutex_top_waiter(lock)->task);
  14185. + lock_top_waiter = rt_mutex_top_waiter(lock);
  14186. + if (prerequeue_top_waiter != lock_top_waiter)
  14187. + rt_mutex_wake_waiter(lock_top_waiter);
  14188. raw_spin_unlock(&lock->wait_lock);
  14189. return 0;
  14190. }
  14191. @@ -740,6 +764,25 @@
  14192. return ret;
  14193. }
  14194. +
  14195. +#define STEAL_NORMAL 0
  14196. +#define STEAL_LATERAL 1
  14197. +
  14198. +/*
  14199. + * Note that RT tasks are excluded from lateral-steals to prevent the
  14200. + * introduction of an unbounded latency
  14201. + */
  14202. +static inline int lock_is_stealable(struct task_struct *task,
  14203. + struct task_struct *pendowner, int mode)
  14204. +{
  14205. + if (mode == STEAL_NORMAL || rt_task(task)) {
  14206. + if (task->prio >= pendowner->prio)
  14207. + return 0;
  14208. + } else if (task->prio > pendowner->prio)
  14209. + return 0;
  14210. + return 1;
  14211. +}
  14212. +
  14213. /*
  14214. * Try to take an rt-mutex
  14215. *
  14216. @@ -750,8 +793,9 @@
  14217. * @waiter: The waiter that is queued to the lock's wait list if the
  14218. * callsite called task_blocked_on_lock(), otherwise NULL
  14219. */
  14220. -static int try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  14221. - struct rt_mutex_waiter *waiter)
  14222. +static int __try_to_take_rt_mutex(struct rt_mutex *lock,
  14223. + struct task_struct *task,
  14224. + struct rt_mutex_waiter *waiter, int mode)
  14225. {
  14226. unsigned long flags;
  14227. @@ -790,8 +834,10 @@
  14228. * If waiter is not the highest priority waiter of
  14229. * @lock, give up.
  14230. */
  14231. - if (waiter != rt_mutex_top_waiter(lock))
  14232. + if (waiter != rt_mutex_top_waiter(lock)) {
  14233. + /* XXX lock_is_stealable() ? */
  14234. return 0;
  14235. + }
  14236. /*
  14237. * We can acquire the lock. Remove the waiter from the
  14238. @@ -809,14 +855,10 @@
  14239. * not need to be dequeued.
  14240. */
  14241. if (rt_mutex_has_waiters(lock)) {
  14242. - /*
  14243. - * If @task->prio is greater than or equal to
  14244. - * the top waiter priority (kernel view),
  14245. - * @task lost.
  14246. - */
  14247. - if (task->prio >= rt_mutex_top_waiter(lock)->prio)
  14248. - return 0;
  14249. + struct task_struct *pown = rt_mutex_top_waiter(lock)->task;
  14250. + if (task != pown && !lock_is_stealable(task, pown, mode))
  14251. + return 0;
  14252. /*
  14253. * The current top waiter stays enqueued. We
  14254. * don't have to change anything in the lock
  14255. @@ -865,6 +907,347 @@
  14256. return 1;
  14257. }
  14258. +#ifdef CONFIG_PREEMPT_RT_FULL
  14259. +/*
  14260. + * preemptible spin_lock functions:
  14261. + */
  14262. +static inline void rt_spin_lock_fastlock(struct rt_mutex *lock,
  14263. + void (*slowfn)(struct rt_mutex *lock))
  14264. +{
  14265. + might_sleep_no_state_check();
  14266. +
  14267. + if (likely(rt_mutex_cmpxchg(lock, NULL, current)))
  14268. + rt_mutex_deadlock_account_lock(lock, current);
  14269. + else
  14270. + slowfn(lock);
  14271. +}
  14272. +
  14273. +static inline void rt_spin_lock_fastunlock(struct rt_mutex *lock,
  14274. + void (*slowfn)(struct rt_mutex *lock))
  14275. +{
  14276. + if (likely(rt_mutex_cmpxchg(lock, current, NULL)))
  14277. + rt_mutex_deadlock_account_unlock(current);
  14278. + else
  14279. + slowfn(lock);
  14280. +}
  14281. +#ifdef CONFIG_SMP
  14282. +/*
  14283. + * Note that owner is a speculative pointer and dereferencing relies
  14284. + * on rcu_read_lock() and the check against the lock owner.
  14285. + */
  14286. +static int adaptive_wait(struct rt_mutex *lock,
  14287. + struct task_struct *owner)
  14288. +{
  14289. + int res = 0;
  14290. +
  14291. + rcu_read_lock();
  14292. + for (;;) {
  14293. + if (owner != rt_mutex_owner(lock))
  14294. + break;
  14295. + /*
  14296. + * Ensure that owner->on_cpu is dereferenced _after_
  14297. + * checking the above to be valid.
  14298. + */
  14299. + barrier();
  14300. + if (!owner->on_cpu) {
  14301. + res = 1;
  14302. + break;
  14303. + }
  14304. + cpu_relax();
  14305. + }
  14306. + rcu_read_unlock();
  14307. + return res;
  14308. +}
  14309. +#else
  14310. +static int adaptive_wait(struct rt_mutex *lock,
  14311. + struct task_struct *orig_owner)
  14312. +{
  14313. + return 1;
  14314. +}
  14315. +#endif
  14316. +
  14317. +# define pi_lock(lock) raw_spin_lock_irq(lock)
  14318. +# define pi_unlock(lock) raw_spin_unlock_irq(lock)
  14319. +
  14320. +static int task_blocks_on_rt_mutex(struct rt_mutex *lock,
  14321. + struct rt_mutex_waiter *waiter,
  14322. + struct task_struct *task,
  14323. + enum rtmutex_chainwalk chwalk);
  14324. +/*
  14325. + * Slow path lock function spin_lock style: this variant is very
  14326. + * careful not to miss any non-lock wakeups.
  14327. + *
  14328. + * We store the current state under p->pi_lock in p->saved_state and
  14329. + * the try_to_wake_up() code handles this accordingly.
  14330. + */
  14331. +static void noinline __sched rt_spin_lock_slowlock(struct rt_mutex *lock)
  14332. +{
  14333. + struct task_struct *lock_owner, *self = current;
  14334. + struct rt_mutex_waiter waiter, *top_waiter;
  14335. + int ret;
  14336. +
  14337. + rt_mutex_init_waiter(&waiter, true);
  14338. +
  14339. + raw_spin_lock(&lock->wait_lock);
  14340. +
  14341. + if (__try_to_take_rt_mutex(lock, self, NULL, STEAL_LATERAL)) {
  14342. + raw_spin_unlock(&lock->wait_lock);
  14343. + return;
  14344. + }
  14345. +
  14346. + BUG_ON(rt_mutex_owner(lock) == self);
  14347. +
  14348. + /*
  14349. + * We save whatever state the task is in and we'll restore it
  14350. + * after acquiring the lock taking real wakeups into account
  14351. + * as well. We are serialized via pi_lock against wakeups. See
  14352. + * try_to_wake_up().
  14353. + */
  14354. + pi_lock(&self->pi_lock);
  14355. + self->saved_state = self->state;
  14356. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  14357. + pi_unlock(&self->pi_lock);
  14358. +
  14359. + ret = task_blocks_on_rt_mutex(lock, &waiter, self, 0);
  14360. + BUG_ON(ret);
  14361. +
  14362. + for (;;) {
  14363. + /* Try to acquire the lock again. */
  14364. + if (__try_to_take_rt_mutex(lock, self, &waiter, STEAL_LATERAL))
  14365. + break;
  14366. +
  14367. + top_waiter = rt_mutex_top_waiter(lock);
  14368. + lock_owner = rt_mutex_owner(lock);
  14369. +
  14370. + raw_spin_unlock(&lock->wait_lock);
  14371. +
  14372. + debug_rt_mutex_print_deadlock(&waiter);
  14373. +
  14374. + if (top_waiter != &waiter || adaptive_wait(lock, lock_owner))
  14375. + schedule_rt_mutex(lock);
  14376. +
  14377. + raw_spin_lock(&lock->wait_lock);
  14378. +
  14379. + pi_lock(&self->pi_lock);
  14380. + __set_current_state_no_track(TASK_UNINTERRUPTIBLE);
  14381. + pi_unlock(&self->pi_lock);
  14382. + }
  14383. +
  14384. + /*
  14385. + * Restore the task state to current->saved_state. We set it
  14386. + * to the original state above and the try_to_wake_up() code
  14387. + * has possibly updated it when a real (non-rtmutex) wakeup
  14388. + * happened while we were blocked. Clear saved_state so
  14389. + * try_to_wakeup() does not get confused.
  14390. + */
  14391. + pi_lock(&self->pi_lock);
  14392. + __set_current_state_no_track(self->saved_state);
  14393. + self->saved_state = TASK_RUNNING;
  14394. + pi_unlock(&self->pi_lock);
  14395. +
  14396. + /*
  14397. + * try_to_take_rt_mutex() sets the waiter bit
  14398. + * unconditionally. We might have to fix that up:
  14399. + */
  14400. + fixup_rt_mutex_waiters(lock);
  14401. +
  14402. + BUG_ON(rt_mutex_has_waiters(lock) && &waiter == rt_mutex_top_waiter(lock));
  14403. + BUG_ON(!RB_EMPTY_NODE(&waiter.tree_entry));
  14404. +
  14405. + raw_spin_unlock(&lock->wait_lock);
  14406. +
  14407. + debug_rt_mutex_free_waiter(&waiter);
  14408. +}
  14409. +
  14410. +static void wakeup_next_waiter(struct rt_mutex *lock);
  14411. +/*
  14412. + * Slow path to release a rt_mutex spin_lock style
  14413. + */
  14414. +static void noinline __sched rt_spin_lock_slowunlock(struct rt_mutex *lock)
  14415. +{
  14416. + raw_spin_lock(&lock->wait_lock);
  14417. +
  14418. + debug_rt_mutex_unlock(lock);
  14419. +
  14420. + rt_mutex_deadlock_account_unlock(current);
  14421. +
  14422. + if (!rt_mutex_has_waiters(lock)) {
  14423. + lock->owner = NULL;
  14424. + raw_spin_unlock(&lock->wait_lock);
  14425. + return;
  14426. + }
  14427. +
  14428. + wakeup_next_waiter(lock);
  14429. +
  14430. + raw_spin_unlock(&lock->wait_lock);
  14431. +
  14432. + /* Undo pi boosting.when necessary */
  14433. + rt_mutex_adjust_prio(current);
  14434. +}
  14435. +
  14436. +void __lockfunc rt_spin_lock(spinlock_t *lock)
  14437. +{
  14438. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
  14439. + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
  14440. +}
  14441. +EXPORT_SYMBOL(rt_spin_lock);
  14442. +
  14443. +void __lockfunc __rt_spin_lock(struct rt_mutex *lock)
  14444. +{
  14445. + rt_spin_lock_fastlock(lock, rt_spin_lock_slowlock);
  14446. +}
  14447. +EXPORT_SYMBOL(__rt_spin_lock);
  14448. +
  14449. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  14450. +void __lockfunc rt_spin_lock_nested(spinlock_t *lock, int subclass)
  14451. +{
  14452. + rt_spin_lock_fastlock(&lock->lock, rt_spin_lock_slowlock);
  14453. + spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_);
  14454. +}
  14455. +EXPORT_SYMBOL(rt_spin_lock_nested);
  14456. +#endif
  14457. +
  14458. +void __lockfunc rt_spin_unlock(spinlock_t *lock)
  14459. +{
  14460. + /* NOTE: we always pass in '1' for nested, for simplicity */
  14461. + spin_release(&lock->dep_map, 1, _RET_IP_);
  14462. + rt_spin_lock_fastunlock(&lock->lock, rt_spin_lock_slowunlock);
  14463. +}
  14464. +EXPORT_SYMBOL(rt_spin_unlock);
  14465. +
  14466. +void __lockfunc __rt_spin_unlock(struct rt_mutex *lock)
  14467. +{
  14468. + rt_spin_lock_fastunlock(lock, rt_spin_lock_slowunlock);
  14469. +}
  14470. +EXPORT_SYMBOL(__rt_spin_unlock);
  14471. +
  14472. +/*
  14473. + * Wait for the lock to get unlocked: instead of polling for an unlock
  14474. + * (like raw spinlocks do), we lock and unlock, to force the kernel to
  14475. + * schedule if there's contention:
  14476. + */
  14477. +void __lockfunc rt_spin_unlock_wait(spinlock_t *lock)
  14478. +{
  14479. + spin_lock(lock);
  14480. + spin_unlock(lock);
  14481. +}
  14482. +EXPORT_SYMBOL(rt_spin_unlock_wait);
  14483. +
  14484. +int __lockfunc __rt_spin_trylock(struct rt_mutex *lock)
  14485. +{
  14486. + return rt_mutex_trylock(lock);
  14487. +}
  14488. +
  14489. +int __lockfunc rt_spin_trylock(spinlock_t *lock)
  14490. +{
  14491. + int ret = rt_mutex_trylock(&lock->lock);
  14492. +
  14493. + if (ret)
  14494. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  14495. + return ret;
  14496. +}
  14497. +EXPORT_SYMBOL(rt_spin_trylock);
  14498. +
  14499. +int __lockfunc rt_spin_trylock_bh(spinlock_t *lock)
  14500. +{
  14501. + int ret;
  14502. +
  14503. + local_bh_disable();
  14504. + ret = rt_mutex_trylock(&lock->lock);
  14505. + if (ret) {
  14506. + migrate_disable();
  14507. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  14508. + } else
  14509. + local_bh_enable();
  14510. + return ret;
  14511. +}
  14512. +EXPORT_SYMBOL(rt_spin_trylock_bh);
  14513. +
  14514. +int __lockfunc rt_spin_trylock_irqsave(spinlock_t *lock, unsigned long *flags)
  14515. +{
  14516. + int ret;
  14517. +
  14518. + *flags = 0;
  14519. + ret = rt_mutex_trylock(&lock->lock);
  14520. + if (ret) {
  14521. + migrate_disable();
  14522. + spin_acquire(&lock->dep_map, 0, 1, _RET_IP_);
  14523. + }
  14524. + return ret;
  14525. +}
  14526. +EXPORT_SYMBOL(rt_spin_trylock_irqsave);
  14527. +
  14528. +int atomic_dec_and_spin_lock(atomic_t *atomic, spinlock_t *lock)
  14529. +{
  14530. + /* Subtract 1 from counter unless that drops it to 0 (ie. it was 1) */
  14531. + if (atomic_add_unless(atomic, -1, 1))
  14532. + return 0;
  14533. + migrate_disable();
  14534. + rt_spin_lock(lock);
  14535. + if (atomic_dec_and_test(atomic))
  14536. + return 1;
  14537. + rt_spin_unlock(lock);
  14538. + migrate_enable();
  14539. + return 0;
  14540. +}
  14541. +EXPORT_SYMBOL(atomic_dec_and_spin_lock);
  14542. +
  14543. + void
  14544. +__rt_spin_lock_init(spinlock_t *lock, char *name, struct lock_class_key *key)
  14545. +{
  14546. +#ifdef CONFIG_DEBUG_LOCK_ALLOC
  14547. + /*
  14548. + * Make sure we are not reinitializing a held lock:
  14549. + */
  14550. + debug_check_no_locks_freed((void *)lock, sizeof(*lock));
  14551. + lockdep_init_map(&lock->dep_map, name, key, 0);
  14552. +#endif
  14553. +}
  14554. +EXPORT_SYMBOL(__rt_spin_lock_init);
  14555. +
  14556. +#endif /* PREEMPT_RT_FULL */
  14557. +
  14558. +#ifdef CONFIG_PREEMPT_RT_FULL
  14559. + static inline int __sched
  14560. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  14561. +{
  14562. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  14563. + struct ww_acquire_ctx *hold_ctx = ACCESS_ONCE(ww->ctx);
  14564. +
  14565. + if (!hold_ctx)
  14566. + return 0;
  14567. +
  14568. + if (unlikely(ctx == hold_ctx))
  14569. + return -EALREADY;
  14570. +
  14571. + if (ctx->stamp - hold_ctx->stamp <= LONG_MAX &&
  14572. + (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) {
  14573. +#ifdef CONFIG_DEBUG_MUTEXES
  14574. + DEBUG_LOCKS_WARN_ON(ctx->contending_lock);
  14575. + ctx->contending_lock = ww;
  14576. +#endif
  14577. + return -EDEADLK;
  14578. + }
  14579. +
  14580. + return 0;
  14581. +}
  14582. +#else
  14583. + static inline int __sched
  14584. +__mutex_lock_check_stamp(struct rt_mutex *lock, struct ww_acquire_ctx *ctx)
  14585. +{
  14586. + BUG();
  14587. + return 0;
  14588. +}
  14589. +
  14590. +#endif
  14591. +
  14592. +static inline int
  14593. +try_to_take_rt_mutex(struct rt_mutex *lock, struct task_struct *task,
  14594. + struct rt_mutex_waiter *waiter)
  14595. +{
  14596. + return __try_to_take_rt_mutex(lock, task, waiter, STEAL_NORMAL);
  14597. +}
  14598. +
  14599. /*
  14600. * Task blocks on lock.
  14601. *
  14602. @@ -896,6 +1279,23 @@
  14603. return -EDEADLK;
  14604. raw_spin_lock_irqsave(&task->pi_lock, flags);
  14605. +
  14606. + /*
  14607. + * In the case of futex requeue PI, this will be a proxy
  14608. + * lock. The task will wake unaware that it is enqueueed on
  14609. + * this lock. Avoid blocking on two locks and corrupting
  14610. + * pi_blocked_on via the PI_WAKEUP_INPROGRESS
  14611. + * flag. futex_wait_requeue_pi() sets this when it wakes up
  14612. + * before requeue (due to a signal or timeout). Do not enqueue
  14613. + * the task if PI_WAKEUP_INPROGRESS is set.
  14614. + */
  14615. + if (task != current && task->pi_blocked_on == PI_WAKEUP_INPROGRESS) {
  14616. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  14617. + return -EAGAIN;
  14618. + }
  14619. +
  14620. + BUG_ON(rt_mutex_real_waiter(task->pi_blocked_on));
  14621. +
  14622. __rt_mutex_adjust_prio(task);
  14623. waiter->task = task;
  14624. waiter->lock = lock;
  14625. @@ -919,7 +1319,7 @@
  14626. rt_mutex_enqueue_pi(owner, waiter);
  14627. __rt_mutex_adjust_prio(owner);
  14628. - if (owner->pi_blocked_on)
  14629. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  14630. chain_walk = 1;
  14631. } else if (rt_mutex_cond_detect_deadlock(waiter, chwalk)) {
  14632. chain_walk = 1;
  14633. @@ -957,8 +1357,9 @@
  14634. /*
  14635. * Wake up the next waiter on the lock.
  14636. *
  14637. - * Remove the top waiter from the current tasks pi waiter list and
  14638. - * wake it up.
  14639. + * Remove the top waiter from the current tasks pi waiter list,
  14640. + * wake it up and return whether the current task needs to undo
  14641. + * a potential priority boosting.
  14642. *
  14643. * Called with lock->wait_lock held.
  14644. */
  14645. @@ -996,7 +1397,7 @@
  14646. * long as we hold lock->wait_lock. The waiter task needs to
  14647. * acquire it in order to dequeue the waiter.
  14648. */
  14649. - wake_up_process(waiter->task);
  14650. + rt_mutex_wake_waiter(waiter);
  14651. }
  14652. /*
  14653. @@ -1010,7 +1411,7 @@
  14654. {
  14655. bool is_top_waiter = (waiter == rt_mutex_top_waiter(lock));
  14656. struct task_struct *owner = rt_mutex_owner(lock);
  14657. - struct rt_mutex *next_lock;
  14658. + struct rt_mutex *next_lock = NULL;
  14659. unsigned long flags;
  14660. raw_spin_lock_irqsave(&current->pi_lock, flags);
  14661. @@ -1035,7 +1436,8 @@
  14662. __rt_mutex_adjust_prio(owner);
  14663. /* Store the lock on which owner is blocked or NULL */
  14664. - next_lock = task_blocked_on_lock(owner);
  14665. + if (rt_mutex_real_waiter(owner->pi_blocked_on))
  14666. + next_lock = task_blocked_on_lock(owner);
  14667. raw_spin_unlock_irqrestore(&owner->pi_lock, flags);
  14668. @@ -1071,17 +1473,17 @@
  14669. raw_spin_lock_irqsave(&task->pi_lock, flags);
  14670. waiter = task->pi_blocked_on;
  14671. - if (!waiter || (waiter->prio == task->prio &&
  14672. + if (!rt_mutex_real_waiter(waiter) || (waiter->prio == task->prio &&
  14673. !dl_prio(task->prio))) {
  14674. raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  14675. return;
  14676. }
  14677. next_lock = waiter->lock;
  14678. - raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  14679. /* gets dropped in rt_mutex_adjust_prio_chain()! */
  14680. get_task_struct(task);
  14681. + raw_spin_unlock_irqrestore(&task->pi_lock, flags);
  14682. rt_mutex_adjust_prio_chain(task, RT_MUTEX_MIN_CHAINWALK, NULL,
  14683. next_lock, NULL, task);
  14684. }
  14685. @@ -1099,7 +1501,8 @@
  14686. static int __sched
  14687. __rt_mutex_slowlock(struct rt_mutex *lock, int state,
  14688. struct hrtimer_sleeper *timeout,
  14689. - struct rt_mutex_waiter *waiter)
  14690. + struct rt_mutex_waiter *waiter,
  14691. + struct ww_acquire_ctx *ww_ctx)
  14692. {
  14693. int ret = 0;
  14694. @@ -1122,6 +1525,12 @@
  14695. break;
  14696. }
  14697. + if (ww_ctx && ww_ctx->acquired > 0) {
  14698. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  14699. + if (ret)
  14700. + break;
  14701. + }
  14702. +
  14703. raw_spin_unlock(&lock->wait_lock);
  14704. debug_rt_mutex_print_deadlock(waiter);
  14705. @@ -1156,25 +1565,102 @@
  14706. }
  14707. }
  14708. +static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww,
  14709. + struct ww_acquire_ctx *ww_ctx)
  14710. +{
  14711. +#ifdef CONFIG_DEBUG_MUTEXES
  14712. + /*
  14713. + * If this WARN_ON triggers, you used ww_mutex_lock to acquire,
  14714. + * but released with a normal mutex_unlock in this call.
  14715. + *
  14716. + * This should never happen, always use ww_mutex_unlock.
  14717. + */
  14718. + DEBUG_LOCKS_WARN_ON(ww->ctx);
  14719. +
  14720. + /*
  14721. + * Not quite done after calling ww_acquire_done() ?
  14722. + */
  14723. + DEBUG_LOCKS_WARN_ON(ww_ctx->done_acquire);
  14724. +
  14725. + if (ww_ctx->contending_lock) {
  14726. + /*
  14727. + * After -EDEADLK you tried to
  14728. + * acquire a different ww_mutex? Bad!
  14729. + */
  14730. + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock != ww);
  14731. +
  14732. + /*
  14733. + * You called ww_mutex_lock after receiving -EDEADLK,
  14734. + * but 'forgot' to unlock everything else first?
  14735. + */
  14736. + DEBUG_LOCKS_WARN_ON(ww_ctx->acquired > 0);
  14737. + ww_ctx->contending_lock = NULL;
  14738. + }
  14739. +
  14740. + /*
  14741. + * Naughty, using a different class will lead to undefined behavior!
  14742. + */
  14743. + DEBUG_LOCKS_WARN_ON(ww_ctx->ww_class != ww->ww_class);
  14744. +#endif
  14745. + ww_ctx->acquired++;
  14746. +}
  14747. +
  14748. +#ifdef CONFIG_PREEMPT_RT_FULL
  14749. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  14750. + struct ww_acquire_ctx *ww_ctx)
  14751. +{
  14752. + struct ww_mutex *ww = container_of(lock, struct ww_mutex, base.lock);
  14753. + struct rt_mutex_waiter *waiter, *n;
  14754. +
  14755. + /*
  14756. + * This branch gets optimized out for the common case,
  14757. + * and is only important for ww_mutex_lock.
  14758. + */
  14759. + ww_mutex_lock_acquired(ww, ww_ctx);
  14760. + ww->ctx = ww_ctx;
  14761. +
  14762. + /*
  14763. + * Give any possible sleeping processes the chance to wake up,
  14764. + * so they can recheck if they have to back off.
  14765. + */
  14766. + rbtree_postorder_for_each_entry_safe(waiter, n, &lock->waiters,
  14767. + tree_entry) {
  14768. + /* XXX debug rt mutex waiter wakeup */
  14769. +
  14770. + BUG_ON(waiter->lock != lock);
  14771. + rt_mutex_wake_waiter(waiter);
  14772. + }
  14773. +}
  14774. +
  14775. +#else
  14776. +
  14777. +static void ww_mutex_account_lock(struct rt_mutex *lock,
  14778. + struct ww_acquire_ctx *ww_ctx)
  14779. +{
  14780. + BUG();
  14781. +}
  14782. +#endif
  14783. +
  14784. /*
  14785. * Slow path lock function:
  14786. */
  14787. static int __sched
  14788. rt_mutex_slowlock(struct rt_mutex *lock, int state,
  14789. struct hrtimer_sleeper *timeout,
  14790. - enum rtmutex_chainwalk chwalk)
  14791. + enum rtmutex_chainwalk chwalk,
  14792. + struct ww_acquire_ctx *ww_ctx)
  14793. {
  14794. struct rt_mutex_waiter waiter;
  14795. int ret = 0;
  14796. - debug_rt_mutex_init_waiter(&waiter);
  14797. - RB_CLEAR_NODE(&waiter.pi_tree_entry);
  14798. - RB_CLEAR_NODE(&waiter.tree_entry);
  14799. + rt_mutex_init_waiter(&waiter, false);
  14800. raw_spin_lock(&lock->wait_lock);
  14801. /* Try to acquire the lock again: */
  14802. if (try_to_take_rt_mutex(lock, current, NULL)) {
  14803. + if (ww_ctx)
  14804. + ww_mutex_account_lock(lock, ww_ctx);
  14805. raw_spin_unlock(&lock->wait_lock);
  14806. return 0;
  14807. }
  14808. @@ -1192,13 +1678,23 @@
  14809. if (likely(!ret))
  14810. /* sleep on the mutex */
  14811. - ret = __rt_mutex_slowlock(lock, state, timeout, &waiter);
  14812. + ret = __rt_mutex_slowlock(lock, state, timeout, &waiter,
  14813. + ww_ctx);
  14814. + else if (ww_ctx) {
  14815. + /* ww_mutex received EDEADLK, let it become EALREADY */
  14816. + ret = __mutex_lock_check_stamp(lock, ww_ctx);
  14817. + BUG_ON(!ret);
  14818. + }
  14819. if (unlikely(ret)) {
  14820. __set_current_state(TASK_RUNNING);
  14821. if (rt_mutex_has_waiters(lock))
  14822. remove_waiter(lock, &waiter);
  14823. - rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  14824. + /* ww_mutex want to report EDEADLK/EALREADY, let them */
  14825. + if (!ww_ctx)
  14826. + rt_mutex_handle_deadlock(ret, chwalk, &waiter);
  14827. + } else if (ww_ctx) {
  14828. + ww_mutex_account_lock(lock, ww_ctx);
  14829. }
  14830. /*
  14831. @@ -1255,7 +1751,7 @@
  14832. /*
  14833. * Slow path to release a rt-mutex:
  14834. */
  14835. -static void __sched
  14836. +static bool __sched
  14837. rt_mutex_slowunlock(struct rt_mutex *lock)
  14838. {
  14839. raw_spin_lock(&lock->wait_lock);
  14840. @@ -1298,7 +1794,7 @@
  14841. while (!rt_mutex_has_waiters(lock)) {
  14842. /* Drops lock->wait_lock ! */
  14843. if (unlock_rt_mutex_safe(lock) == true)
  14844. - return;
  14845. + return false;
  14846. /* Relock the rtmutex and try again */
  14847. raw_spin_lock(&lock->wait_lock);
  14848. }
  14849. @@ -1311,8 +1807,7 @@
  14850. raw_spin_unlock(&lock->wait_lock);
  14851. - /* Undo pi boosting if necessary: */
  14852. - rt_mutex_adjust_prio(current);
  14853. + return true;
  14854. }
  14855. /*
  14856. @@ -1323,31 +1818,36 @@
  14857. */
  14858. static inline int
  14859. rt_mutex_fastlock(struct rt_mutex *lock, int state,
  14860. + struct ww_acquire_ctx *ww_ctx,
  14861. int (*slowfn)(struct rt_mutex *lock, int state,
  14862. struct hrtimer_sleeper *timeout,
  14863. - enum rtmutex_chainwalk chwalk))
  14864. + enum rtmutex_chainwalk chwalk,
  14865. + struct ww_acquire_ctx *ww_ctx))
  14866. {
  14867. if (likely(rt_mutex_cmpxchg(lock, NULL, current))) {
  14868. rt_mutex_deadlock_account_lock(lock, current);
  14869. return 0;
  14870. } else
  14871. - return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK);
  14872. + return slowfn(lock, state, NULL, RT_MUTEX_MIN_CHAINWALK,
  14873. + ww_ctx);
  14874. }
  14875. static inline int
  14876. rt_mutex_timed_fastlock(struct rt_mutex *lock, int state,
  14877. struct hrtimer_sleeper *timeout,
  14878. enum rtmutex_chainwalk chwalk,
  14879. + struct ww_acquire_ctx *ww_ctx,
  14880. int (*slowfn)(struct rt_mutex *lock, int state,
  14881. struct hrtimer_sleeper *timeout,
  14882. - enum rtmutex_chainwalk chwalk))
  14883. + enum rtmutex_chainwalk chwalk,
  14884. + struct ww_acquire_ctx *ww_ctx))
  14885. {
  14886. if (chwalk == RT_MUTEX_MIN_CHAINWALK &&
  14887. likely(rt_mutex_cmpxchg(lock, NULL, current))) {
  14888. rt_mutex_deadlock_account_lock(lock, current);
  14889. return 0;
  14890. } else
  14891. - return slowfn(lock, state, timeout, chwalk);
  14892. + return slowfn(lock, state, timeout, chwalk, ww_ctx);
  14893. }
  14894. static inline int
  14895. @@ -1363,12 +1863,14 @@
  14896. static inline void
  14897. rt_mutex_fastunlock(struct rt_mutex *lock,
  14898. - void (*slowfn)(struct rt_mutex *lock))
  14899. + bool (*slowfn)(struct rt_mutex *lock))
  14900. {
  14901. - if (likely(rt_mutex_cmpxchg(lock, current, NULL)))
  14902. + if (likely(rt_mutex_cmpxchg(lock, current, NULL))) {
  14903. rt_mutex_deadlock_account_unlock(current);
  14904. - else
  14905. - slowfn(lock);
  14906. + } else if (slowfn(lock)) {
  14907. + /* Undo pi boosting if necessary: */
  14908. + rt_mutex_adjust_prio(current);
  14909. + }
  14910. }
  14911. /**
  14912. @@ -1380,7 +1882,7 @@
  14913. {
  14914. might_sleep();
  14915. - rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, rt_mutex_slowlock);
  14916. + rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, NULL, rt_mutex_slowlock);
  14917. }
  14918. EXPORT_SYMBOL_GPL(rt_mutex_lock);
  14919. @@ -1397,7 +1899,7 @@
  14920. {
  14921. might_sleep();
  14922. - return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, rt_mutex_slowlock);
  14923. + return rt_mutex_fastlock(lock, TASK_INTERRUPTIBLE, NULL, rt_mutex_slowlock);
  14924. }
  14925. EXPORT_SYMBOL_GPL(rt_mutex_lock_interruptible);
  14926. @@ -1410,11 +1912,30 @@
  14927. might_sleep();
  14928. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  14929. - RT_MUTEX_FULL_CHAINWALK,
  14930. + RT_MUTEX_FULL_CHAINWALK, NULL,
  14931. rt_mutex_slowlock);
  14932. }
  14933. /**
  14934. + * rt_mutex_lock_killable - lock a rt_mutex killable
  14935. + *
  14936. + * @lock: the rt_mutex to be locked
  14937. + * @detect_deadlock: deadlock detection on/off
  14938. + *
  14939. + * Returns:
  14940. + * 0 on success
  14941. + * -EINTR when interrupted by a signal
  14942. + * -EDEADLK when the lock would deadlock (when deadlock detection is on)
  14943. + */
  14944. +int __sched rt_mutex_lock_killable(struct rt_mutex *lock)
  14945. +{
  14946. + might_sleep();
  14947. +
  14948. + return rt_mutex_fastlock(lock, TASK_KILLABLE, NULL, rt_mutex_slowlock);
  14949. +}
  14950. +EXPORT_SYMBOL_GPL(rt_mutex_lock_killable);
  14951. +
  14952. +/**
  14953. * rt_mutex_timed_lock - lock a rt_mutex interruptible
  14954. * the timeout structure is provided
  14955. * by the caller
  14956. @@ -1434,6 +1955,7 @@
  14957. return rt_mutex_timed_fastlock(lock, TASK_INTERRUPTIBLE, timeout,
  14958. RT_MUTEX_MIN_CHAINWALK,
  14959. + NULL,
  14960. rt_mutex_slowlock);
  14961. }
  14962. EXPORT_SYMBOL_GPL(rt_mutex_timed_lock);
  14963. @@ -1463,6 +1985,22 @@
  14964. EXPORT_SYMBOL_GPL(rt_mutex_unlock);
  14965. /**
  14966. + * rt_mutex_futex_unlock - Futex variant of rt_mutex_unlock
  14967. + * @lock: the rt_mutex to be unlocked
  14968. + *
  14969. + * Returns: true/false indicating whether priority adjustment is
  14970. + * required or not.
  14971. + */
  14972. +bool __sched rt_mutex_futex_unlock(struct rt_mutex *lock)
  14973. +{
  14974. + if (likely(rt_mutex_cmpxchg(lock, current, NULL))) {
  14975. + rt_mutex_deadlock_account_unlock(current);
  14976. + return false;
  14977. + }
  14978. + return rt_mutex_slowunlock(lock);
  14979. +}
  14980. +
  14981. +/**
  14982. * rt_mutex_destroy - mark a mutex unusable
  14983. * @lock: the mutex to be destroyed
  14984. *
  14985. @@ -1492,13 +2030,12 @@
  14986. void __rt_mutex_init(struct rt_mutex *lock, const char *name)
  14987. {
  14988. lock->owner = NULL;
  14989. - raw_spin_lock_init(&lock->wait_lock);
  14990. lock->waiters = RB_ROOT;
  14991. lock->waiters_leftmost = NULL;
  14992. debug_rt_mutex_init(lock, name);
  14993. }
  14994. -EXPORT_SYMBOL_GPL(__rt_mutex_init);
  14995. +EXPORT_SYMBOL(__rt_mutex_init);
  14996. /**
  14997. * rt_mutex_init_proxy_locked - initialize and lock a rt_mutex on behalf of a
  14998. @@ -1513,7 +2050,7 @@
  14999. void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  15000. struct task_struct *proxy_owner)
  15001. {
  15002. - __rt_mutex_init(lock, NULL);
  15003. + rt_mutex_init(lock);
  15004. debug_rt_mutex_proxy_lock(lock, proxy_owner);
  15005. rt_mutex_set_owner(lock, proxy_owner);
  15006. rt_mutex_deadlock_account_lock(lock, proxy_owner);
  15007. @@ -1561,6 +2098,35 @@
  15008. return 1;
  15009. }
  15010. +#ifdef CONFIG_PREEMPT_RT_FULL
  15011. + /*
  15012. + * In PREEMPT_RT there's an added race.
  15013. + * If the task, that we are about to requeue, times out,
  15014. + * it can set the PI_WAKEUP_INPROGRESS. This tells the requeue
  15015. + * to skip this task. But right after the task sets
  15016. + * its pi_blocked_on to PI_WAKEUP_INPROGRESS it can then
  15017. + * block on the spin_lock(&hb->lock), which in RT is an rtmutex.
  15018. + * This will replace the PI_WAKEUP_INPROGRESS with the actual
  15019. + * lock that it blocks on. We *must not* place this task
  15020. + * on this proxy lock in that case.
  15021. + *
  15022. + * To prevent this race, we first take the task's pi_lock
  15023. + * and check if it has updated its pi_blocked_on. If it has,
  15024. + * we assume that it woke up and we return -EAGAIN.
  15025. + * Otherwise, we set the task's pi_blocked_on to
  15026. + * PI_REQUEUE_INPROGRESS, so that if the task is waking up
  15027. + * it will know that we are in the process of requeuing it.
  15028. + */
  15029. + raw_spin_lock_irq(&task->pi_lock);
  15030. + if (task->pi_blocked_on) {
  15031. + raw_spin_unlock_irq(&task->pi_lock);
  15032. + raw_spin_unlock(&lock->wait_lock);
  15033. + return -EAGAIN;
  15034. + }
  15035. + task->pi_blocked_on = PI_REQUEUE_INPROGRESS;
  15036. + raw_spin_unlock_irq(&task->pi_lock);
  15037. +#endif
  15038. +
  15039. /* We enforce deadlock detection for futexes */
  15040. ret = task_blocks_on_rt_mutex(lock, waiter, task,
  15041. RT_MUTEX_FULL_CHAINWALK);
  15042. @@ -1631,7 +2197,7 @@
  15043. set_current_state(TASK_INTERRUPTIBLE);
  15044. /* sleep on the mutex */
  15045. - ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter);
  15046. + ret = __rt_mutex_slowlock(lock, TASK_INTERRUPTIBLE, to, waiter, NULL);
  15047. if (unlikely(ret))
  15048. remove_waiter(lock, waiter);
  15049. @@ -1646,3 +2212,89 @@
  15050. return ret;
  15051. }
  15052. +
  15053. +static inline int
  15054. +ww_mutex_deadlock_injection(struct ww_mutex *lock, struct ww_acquire_ctx *ctx)
  15055. +{
  15056. +#ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
  15057. + unsigned tmp;
  15058. +
  15059. + if (ctx->deadlock_inject_countdown-- == 0) {
  15060. + tmp = ctx->deadlock_inject_interval;
  15061. + if (tmp > UINT_MAX/4)
  15062. + tmp = UINT_MAX;
  15063. + else
  15064. + tmp = tmp*2 + tmp + tmp/2;
  15065. +
  15066. + ctx->deadlock_inject_interval = tmp;
  15067. + ctx->deadlock_inject_countdown = tmp;
  15068. + ctx->contending_lock = lock;
  15069. +
  15070. + ww_mutex_unlock(lock);
  15071. +
  15072. + return -EDEADLK;
  15073. + }
  15074. +#endif
  15075. +
  15076. + return 0;
  15077. +}
  15078. +
  15079. +#ifdef CONFIG_PREEMPT_RT_FULL
  15080. +int __sched
  15081. +__ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  15082. +{
  15083. + int ret;
  15084. +
  15085. + might_sleep();
  15086. +
  15087. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  15088. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_INTERRUPTIBLE, NULL, 0, ww_ctx);
  15089. + if (ret)
  15090. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  15091. + else if (!ret && ww_ctx->acquired > 1)
  15092. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  15093. +
  15094. + return ret;
  15095. +}
  15096. +EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible);
  15097. +
  15098. +int __sched
  15099. +__ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ww_ctx)
  15100. +{
  15101. + int ret;
  15102. +
  15103. + might_sleep();
  15104. +
  15105. + mutex_acquire_nest(&lock->base.dep_map, 0, 0, &ww_ctx->dep_map, _RET_IP_);
  15106. + ret = rt_mutex_slowlock(&lock->base.lock, TASK_UNINTERRUPTIBLE, NULL, 0, ww_ctx);
  15107. + if (ret)
  15108. + mutex_release(&lock->base.dep_map, 1, _RET_IP_);
  15109. + else if (!ret && ww_ctx->acquired > 1)
  15110. + return ww_mutex_deadlock_injection(lock, ww_ctx);
  15111. +
  15112. + return ret;
  15113. +}
  15114. +EXPORT_SYMBOL_GPL(__ww_mutex_lock);
  15115. +
  15116. +void __sched ww_mutex_unlock(struct ww_mutex *lock)
  15117. +{
  15118. + int nest = !!lock->ctx;
  15119. +
  15120. + /*
  15121. + * The unlocking fastpath is the 0->1 transition from 'locked'
  15122. + * into 'unlocked' state:
  15123. + */
  15124. + if (nest) {
  15125. +#ifdef CONFIG_DEBUG_MUTEXES
  15126. + DEBUG_LOCKS_WARN_ON(!lock->ctx->acquired);
  15127. +#endif
  15128. + if (lock->ctx->acquired > 0)
  15129. + lock->ctx->acquired--;
  15130. + lock->ctx = NULL;
  15131. + }
  15132. +
  15133. + mutex_release(&lock->base.dep_map, nest, _RET_IP_);
  15134. + rt_mutex_unlock(&lock->base.lock);
  15135. +}
  15136. +EXPORT_SYMBOL(ww_mutex_unlock);
  15137. +#endif
  15138. diff -Nur linux-4.1.6.orig/kernel/locking/rtmutex_common.h linux-4.1.6/kernel/locking/rtmutex_common.h
  15139. --- linux-4.1.6.orig/kernel/locking/rtmutex_common.h 2015-08-17 05:52:51.000000000 +0200
  15140. +++ linux-4.1.6/kernel/locking/rtmutex_common.h 2015-09-08 23:49:08.101867828 +0200
  15141. @@ -49,6 +49,7 @@
  15142. struct rb_node pi_tree_entry;
  15143. struct task_struct *task;
  15144. struct rt_mutex *lock;
  15145. + bool savestate;
  15146. #ifdef CONFIG_DEBUG_RT_MUTEXES
  15147. unsigned long ip;
  15148. struct pid *deadlock_task_pid;
  15149. @@ -119,6 +120,9 @@
  15150. /*
  15151. * PI-futex support (proxy locking functions, etc.):
  15152. */
  15153. +#define PI_WAKEUP_INPROGRESS ((struct rt_mutex_waiter *) 1)
  15154. +#define PI_REQUEUE_INPROGRESS ((struct rt_mutex_waiter *) 2)
  15155. +
  15156. extern struct task_struct *rt_mutex_next_owner(struct rt_mutex *lock);
  15157. extern void rt_mutex_init_proxy_locked(struct rt_mutex *lock,
  15158. struct task_struct *proxy_owner);
  15159. @@ -132,10 +136,24 @@
  15160. struct rt_mutex_waiter *waiter);
  15161. extern int rt_mutex_timed_futex_lock(struct rt_mutex *l, struct hrtimer_sleeper *to);
  15162. +extern bool rt_mutex_futex_unlock(struct rt_mutex *lock);
  15163. +
  15164. +extern void rt_mutex_adjust_prio(struct task_struct *task);
  15165. +
  15166. #ifdef CONFIG_DEBUG_RT_MUTEXES
  15167. # include "rtmutex-debug.h"
  15168. #else
  15169. # include "rtmutex.h"
  15170. #endif
  15171. +static inline void
  15172. +rt_mutex_init_waiter(struct rt_mutex_waiter *waiter, bool savestate)
  15173. +{
  15174. + debug_rt_mutex_init_waiter(waiter);
  15175. + waiter->task = NULL;
  15176. + waiter->savestate = savestate;
  15177. + RB_CLEAR_NODE(&waiter->pi_tree_entry);
  15178. + RB_CLEAR_NODE(&waiter->tree_entry);
  15179. +}
  15180. +
  15181. #endif
  15182. diff -Nur linux-4.1.6.orig/kernel/locking/spinlock.c linux-4.1.6/kernel/locking/spinlock.c
  15183. --- linux-4.1.6.orig/kernel/locking/spinlock.c 2015-08-17 05:52:51.000000000 +0200
  15184. +++ linux-4.1.6/kernel/locking/spinlock.c 2015-09-08 23:49:08.101867828 +0200
  15185. @@ -124,8 +124,11 @@
  15186. * __[spin|read|write]_lock_bh()
  15187. */
  15188. BUILD_LOCK_OPS(spin, raw_spinlock);
  15189. +
  15190. +#ifndef CONFIG_PREEMPT_RT_FULL
  15191. BUILD_LOCK_OPS(read, rwlock);
  15192. BUILD_LOCK_OPS(write, rwlock);
  15193. +#endif
  15194. #endif
  15195. @@ -209,6 +212,8 @@
  15196. EXPORT_SYMBOL(_raw_spin_unlock_bh);
  15197. #endif
  15198. +#ifndef CONFIG_PREEMPT_RT_FULL
  15199. +
  15200. #ifndef CONFIG_INLINE_READ_TRYLOCK
  15201. int __lockfunc _raw_read_trylock(rwlock_t *lock)
  15202. {
  15203. @@ -353,6 +358,8 @@
  15204. EXPORT_SYMBOL(_raw_write_unlock_bh);
  15205. #endif
  15206. +#endif /* !PREEMPT_RT_FULL */
  15207. +
  15208. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  15209. void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass)
  15210. diff -Nur linux-4.1.6.orig/kernel/locking/spinlock_debug.c linux-4.1.6/kernel/locking/spinlock_debug.c
  15211. --- linux-4.1.6.orig/kernel/locking/spinlock_debug.c 2015-08-17 05:52:51.000000000 +0200
  15212. +++ linux-4.1.6/kernel/locking/spinlock_debug.c 2015-09-08 23:49:08.105867384 +0200
  15213. @@ -31,6 +31,7 @@
  15214. EXPORT_SYMBOL(__raw_spin_lock_init);
  15215. +#ifndef CONFIG_PREEMPT_RT_FULL
  15216. void __rwlock_init(rwlock_t *lock, const char *name,
  15217. struct lock_class_key *key)
  15218. {
  15219. @@ -48,6 +49,7 @@
  15220. }
  15221. EXPORT_SYMBOL(__rwlock_init);
  15222. +#endif
  15223. static void spin_dump(raw_spinlock_t *lock, const char *msg)
  15224. {
  15225. @@ -159,6 +161,7 @@
  15226. arch_spin_unlock(&lock->raw_lock);
  15227. }
  15228. +#ifndef CONFIG_PREEMPT_RT_FULL
  15229. static void rwlock_bug(rwlock_t *lock, const char *msg)
  15230. {
  15231. if (!debug_locks_off())
  15232. @@ -300,3 +303,5 @@
  15233. debug_write_unlock(lock);
  15234. arch_write_unlock(&lock->raw_lock);
  15235. }
  15236. +
  15237. +#endif
  15238. diff -Nur linux-4.1.6.orig/kernel/panic.c linux-4.1.6/kernel/panic.c
  15239. --- linux-4.1.6.orig/kernel/panic.c 2015-08-17 05:52:51.000000000 +0200
  15240. +++ linux-4.1.6/kernel/panic.c 2015-09-08 23:49:08.105867384 +0200
  15241. @@ -387,9 +387,11 @@
  15242. static int init_oops_id(void)
  15243. {
  15244. +#ifndef CONFIG_PREEMPT_RT_FULL
  15245. if (!oops_id)
  15246. get_random_bytes(&oops_id, sizeof(oops_id));
  15247. else
  15248. +#endif
  15249. oops_id++;
  15250. return 0;
  15251. diff -Nur linux-4.1.6.orig/kernel/power/hibernate.c linux-4.1.6/kernel/power/hibernate.c
  15252. --- linux-4.1.6.orig/kernel/power/hibernate.c 2015-08-17 05:52:51.000000000 +0200
  15253. +++ linux-4.1.6/kernel/power/hibernate.c 2015-09-08 23:49:08.105867384 +0200
  15254. @@ -285,6 +285,8 @@
  15255. local_irq_disable();
  15256. + system_state = SYSTEM_SUSPEND;
  15257. +
  15258. error = syscore_suspend();
  15259. if (error) {
  15260. printk(KERN_ERR "PM: Some system devices failed to power down, "
  15261. @@ -314,6 +316,7 @@
  15262. syscore_resume();
  15263. Enable_irqs:
  15264. + system_state = SYSTEM_RUNNING;
  15265. local_irq_enable();
  15266. Enable_cpus:
  15267. @@ -437,6 +440,7 @@
  15268. goto Enable_cpus;
  15269. local_irq_disable();
  15270. + system_state = SYSTEM_SUSPEND;
  15271. error = syscore_suspend();
  15272. if (error)
  15273. @@ -470,6 +474,7 @@
  15274. syscore_resume();
  15275. Enable_irqs:
  15276. + system_state = SYSTEM_RUNNING;
  15277. local_irq_enable();
  15278. Enable_cpus:
  15279. @@ -555,6 +560,7 @@
  15280. goto Platform_finish;
  15281. local_irq_disable();
  15282. + system_state = SYSTEM_SUSPEND;
  15283. syscore_suspend();
  15284. if (pm_wakeup_pending()) {
  15285. error = -EAGAIN;
  15286. @@ -567,6 +573,7 @@
  15287. Power_up:
  15288. syscore_resume();
  15289. + system_state = SYSTEM_RUNNING;
  15290. local_irq_enable();
  15291. enable_nonboot_cpus();
  15292. diff -Nur linux-4.1.6.orig/kernel/power/suspend.c linux-4.1.6/kernel/power/suspend.c
  15293. --- linux-4.1.6.orig/kernel/power/suspend.c 2015-08-17 05:52:51.000000000 +0200
  15294. +++ linux-4.1.6/kernel/power/suspend.c 2015-09-08 23:49:08.105867384 +0200
  15295. @@ -356,6 +356,8 @@
  15296. arch_suspend_disable_irqs();
  15297. BUG_ON(!irqs_disabled());
  15298. + system_state = SYSTEM_SUSPEND;
  15299. +
  15300. error = syscore_suspend();
  15301. if (!error) {
  15302. *wakeup = pm_wakeup_pending();
  15303. @@ -370,6 +372,8 @@
  15304. syscore_resume();
  15305. }
  15306. + system_state = SYSTEM_RUNNING;
  15307. +
  15308. arch_suspend_enable_irqs();
  15309. BUG_ON(irqs_disabled());
  15310. diff -Nur linux-4.1.6.orig/kernel/printk/printk.c linux-4.1.6/kernel/printk/printk.c
  15311. --- linux-4.1.6.orig/kernel/printk/printk.c 2015-08-17 05:52:51.000000000 +0200
  15312. +++ linux-4.1.6/kernel/printk/printk.c 2015-09-08 23:49:08.105867384 +0200
  15313. @@ -1163,6 +1163,7 @@
  15314. {
  15315. char *text;
  15316. int len = 0;
  15317. + int attempts = 0;
  15318. text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
  15319. if (!text)
  15320. @@ -1174,7 +1175,14 @@
  15321. u64 seq;
  15322. u32 idx;
  15323. enum log_flags prev;
  15324. -
  15325. + int num_msg;
  15326. +try_again:
  15327. + attempts++;
  15328. + if (attempts > 10) {
  15329. + len = -EBUSY;
  15330. + goto out;
  15331. + }
  15332. + num_msg = 0;
  15333. if (clear_seq < log_first_seq) {
  15334. /* messages are gone, move to first available one */
  15335. clear_seq = log_first_seq;
  15336. @@ -1195,6 +1203,14 @@
  15337. prev = msg->flags;
  15338. idx = log_next(idx);
  15339. seq++;
  15340. + num_msg++;
  15341. + if (num_msg > 5) {
  15342. + num_msg = 0;
  15343. + raw_spin_unlock_irq(&logbuf_lock);
  15344. + raw_spin_lock_irq(&logbuf_lock);
  15345. + if (clear_seq < log_first_seq)
  15346. + goto try_again;
  15347. + }
  15348. }
  15349. /* move first record forward until length fits into the buffer */
  15350. @@ -1208,6 +1224,14 @@
  15351. prev = msg->flags;
  15352. idx = log_next(idx);
  15353. seq++;
  15354. + num_msg++;
  15355. + if (num_msg > 5) {
  15356. + num_msg = 0;
  15357. + raw_spin_unlock_irq(&logbuf_lock);
  15358. + raw_spin_lock_irq(&logbuf_lock);
  15359. + if (clear_seq < log_first_seq)
  15360. + goto try_again;
  15361. + }
  15362. }
  15363. /* last message fitting into this dump */
  15364. @@ -1248,6 +1272,7 @@
  15365. clear_seq = log_next_seq;
  15366. clear_idx = log_next_idx;
  15367. }
  15368. +out:
  15369. raw_spin_unlock_irq(&logbuf_lock);
  15370. kfree(text);
  15371. @@ -1401,6 +1426,7 @@
  15372. if (!console_drivers)
  15373. return;
  15374. + migrate_disable();
  15375. for_each_console(con) {
  15376. if (exclusive_console && con != exclusive_console)
  15377. continue;
  15378. @@ -1413,6 +1439,7 @@
  15379. continue;
  15380. con->write(con, text, len);
  15381. }
  15382. + migrate_enable();
  15383. }
  15384. /*
  15385. @@ -1473,6 +1500,15 @@
  15386. static int console_trylock_for_printk(void)
  15387. {
  15388. unsigned int cpu = smp_processor_id();
  15389. +#ifdef CONFIG_PREEMPT_RT_FULL
  15390. + int lock = !early_boot_irqs_disabled && (preempt_count() == 0) &&
  15391. + !irqs_disabled();
  15392. +#else
  15393. + int lock = 1;
  15394. +#endif
  15395. +
  15396. + if (!lock)
  15397. + return 0;
  15398. if (!console_trylock())
  15399. return 0;
  15400. @@ -1607,6 +1643,62 @@
  15401. return textlen;
  15402. }
  15403. +#ifdef CONFIG_EARLY_PRINTK
  15404. +struct console *early_console;
  15405. +
  15406. +static void early_vprintk(const char *fmt, va_list ap)
  15407. +{
  15408. + if (early_console) {
  15409. + char buf[512];
  15410. + int n = vscnprintf(buf, sizeof(buf), fmt, ap);
  15411. +
  15412. + early_console->write(early_console, buf, n);
  15413. + }
  15414. +}
  15415. +
  15416. +asmlinkage void early_printk(const char *fmt, ...)
  15417. +{
  15418. + va_list ap;
  15419. +
  15420. + va_start(ap, fmt);
  15421. + early_vprintk(fmt, ap);
  15422. + va_end(ap);
  15423. +}
  15424. +
  15425. +/*
  15426. + * This is independent of any log levels - a global
  15427. + * kill switch that turns off all of printk.
  15428. + *
  15429. + * Used by the NMI watchdog if early-printk is enabled.
  15430. + */
  15431. +static bool __read_mostly printk_killswitch;
  15432. +
  15433. +static int __init force_early_printk_setup(char *str)
  15434. +{
  15435. + printk_killswitch = true;
  15436. + return 0;
  15437. +}
  15438. +early_param("force_early_printk", force_early_printk_setup);
  15439. +
  15440. +void printk_kill(void)
  15441. +{
  15442. + printk_killswitch = true;
  15443. +}
  15444. +
  15445. +static int forced_early_printk(const char *fmt, va_list ap)
  15446. +{
  15447. + if (!printk_killswitch)
  15448. + return 0;
  15449. + early_vprintk(fmt, ap);
  15450. + return 1;
  15451. +}
  15452. +#else
  15453. +static inline int forced_early_printk(const char *fmt, va_list ap)
  15454. +{
  15455. + return 0;
  15456. +}
  15457. +#endif
  15458. +
  15459. asmlinkage int vprintk_emit(int facility, int level,
  15460. const char *dict, size_t dictlen,
  15461. const char *fmt, va_list args)
  15462. @@ -1623,6 +1715,13 @@
  15463. /* cpu currently holding logbuf_lock in this function */
  15464. static unsigned int logbuf_cpu = UINT_MAX;
  15465. + /*
  15466. + * Fall back to early_printk if a debugging subsystem has
  15467. + * killed printk output
  15468. + */
  15469. + if (unlikely(forced_early_printk(fmt, args)))
  15470. + return 1;
  15471. +
  15472. if (level == LOGLEVEL_SCHED) {
  15473. level = LOGLEVEL_DEFAULT;
  15474. in_sched = true;
  15475. @@ -1764,8 +1863,7 @@
  15476. * console_sem which would prevent anyone from printing to
  15477. * console
  15478. */
  15479. - preempt_disable();
  15480. -
  15481. + migrate_disable();
  15482. /*
  15483. * Try to acquire and then immediately release the console
  15484. * semaphore. The release will print out buffers and wake up
  15485. @@ -1773,7 +1871,7 @@
  15486. */
  15487. if (console_trylock_for_printk())
  15488. console_unlock();
  15489. - preempt_enable();
  15490. + migrate_enable();
  15491. lockdep_on();
  15492. }
  15493. @@ -1902,26 +2000,6 @@
  15494. #endif /* CONFIG_PRINTK */
  15495. -#ifdef CONFIG_EARLY_PRINTK
  15496. -struct console *early_console;
  15497. -
  15498. -asmlinkage __visible void early_printk(const char *fmt, ...)
  15499. -{
  15500. - va_list ap;
  15501. - char buf[512];
  15502. - int n;
  15503. -
  15504. - if (!early_console)
  15505. - return;
  15506. -
  15507. - va_start(ap, fmt);
  15508. - n = vscnprintf(buf, sizeof(buf), fmt, ap);
  15509. - va_end(ap);
  15510. -
  15511. - early_console->write(early_console, buf, n);
  15512. -}
  15513. -#endif
  15514. -
  15515. static int __add_preferred_console(char *name, int idx, char *options,
  15516. char *brl_options)
  15517. {
  15518. @@ -2143,11 +2221,16 @@
  15519. goto out;
  15520. len = cont_print_text(text, size);
  15521. +#ifndef CONFIG_PREEMPT_RT_FULL
  15522. raw_spin_unlock(&logbuf_lock);
  15523. stop_critical_timings();
  15524. call_console_drivers(cont.level, text, len);
  15525. start_critical_timings();
  15526. local_irq_restore(flags);
  15527. +#else
  15528. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  15529. + call_console_drivers(cont.level, text, len);
  15530. +#endif
  15531. return;
  15532. out:
  15533. raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  15534. @@ -2235,12 +2318,17 @@
  15535. console_idx = log_next(console_idx);
  15536. console_seq++;
  15537. console_prev = msg->flags;
  15538. +#ifdef CONFIG_PREEMPT_RT_FULL
  15539. + raw_spin_unlock_irqrestore(&logbuf_lock, flags);
  15540. + call_console_drivers(level, text, len);
  15541. +#else
  15542. raw_spin_unlock(&logbuf_lock);
  15543. stop_critical_timings(); /* don't trace print latency */
  15544. call_console_drivers(level, text, len);
  15545. start_critical_timings();
  15546. local_irq_restore(flags);
  15547. +#endif
  15548. }
  15549. console_locked = 0;
  15550. diff -Nur linux-4.1.6.orig/kernel/ptrace.c linux-4.1.6/kernel/ptrace.c
  15551. --- linux-4.1.6.orig/kernel/ptrace.c 2015-08-17 05:52:51.000000000 +0200
  15552. +++ linux-4.1.6/kernel/ptrace.c 2015-09-08 23:49:08.105867384 +0200
  15553. @@ -129,7 +129,12 @@
  15554. spin_lock_irq(&task->sighand->siglock);
  15555. if (task_is_traced(task) && !__fatal_signal_pending(task)) {
  15556. - task->state = __TASK_TRACED;
  15557. + raw_spin_lock_irq(&task->pi_lock);
  15558. + if (task->state & __TASK_TRACED)
  15559. + task->state = __TASK_TRACED;
  15560. + else
  15561. + task->saved_state = __TASK_TRACED;
  15562. + raw_spin_unlock_irq(&task->pi_lock);
  15563. ret = true;
  15564. }
  15565. spin_unlock_irq(&task->sighand->siglock);
  15566. diff -Nur linux-4.1.6.orig/kernel/rcu/tree.c linux-4.1.6/kernel/rcu/tree.c
  15567. --- linux-4.1.6.orig/kernel/rcu/tree.c 2015-08-17 05:52:51.000000000 +0200
  15568. +++ linux-4.1.6/kernel/rcu/tree.c 2015-09-08 23:49:08.105867384 +0200
  15569. @@ -56,6 +56,11 @@
  15570. #include <linux/random.h>
  15571. #include <linux/ftrace_event.h>
  15572. #include <linux/suspend.h>
  15573. +#include <linux/delay.h>
  15574. +#include <linux/gfp.h>
  15575. +#include <linux/oom.h>
  15576. +#include <linux/smpboot.h>
  15577. +#include "../time/tick-internal.h"
  15578. #include "tree.h"
  15579. #include "rcu.h"
  15580. @@ -220,6 +225,19 @@
  15581. }
  15582. }
  15583. +#ifdef CONFIG_PREEMPT_RT_FULL
  15584. +static void rcu_preempt_qs(void);
  15585. +
  15586. +void rcu_bh_qs(void)
  15587. +{
  15588. + unsigned long flags;
  15589. +
  15590. + /* Callers to this function, rcu_preempt_qs(), must disable irqs. */
  15591. + local_irq_save(flags);
  15592. + rcu_preempt_qs();
  15593. + local_irq_restore(flags);
  15594. +}
  15595. +#else
  15596. void rcu_bh_qs(void)
  15597. {
  15598. if (!__this_cpu_read(rcu_bh_data.passed_quiesce)) {
  15599. @@ -229,6 +247,7 @@
  15600. __this_cpu_write(rcu_bh_data.passed_quiesce, 1);
  15601. }
  15602. }
  15603. +#endif
  15604. static DEFINE_PER_CPU(int, rcu_sched_qs_mask);
  15605. @@ -404,6 +423,7 @@
  15606. }
  15607. EXPORT_SYMBOL_GPL(rcu_batches_completed_sched);
  15608. +#ifndef CONFIG_PREEMPT_RT_FULL
  15609. /*
  15610. * Return the number of RCU BH batches completed thus far for debug & stats.
  15611. */
  15612. @@ -431,6 +451,13 @@
  15613. }
  15614. EXPORT_SYMBOL_GPL(rcu_bh_force_quiescent_state);
  15615. +#else
  15616. +void rcu_force_quiescent_state(void)
  15617. +{
  15618. +}
  15619. +EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  15620. +#endif
  15621. +
  15622. /*
  15623. * Force a quiescent state for RCU-sched.
  15624. */
  15625. @@ -1545,7 +1572,7 @@
  15626. !ACCESS_ONCE(rsp->gp_flags) ||
  15627. !rsp->gp_kthread)
  15628. return;
  15629. - wake_up(&rsp->gp_wq);
  15630. + swait_wake(&rsp->gp_wq);
  15631. }
  15632. /*
  15633. @@ -1986,7 +2013,7 @@
  15634. ACCESS_ONCE(rsp->gpnum),
  15635. TPS("reqwait"));
  15636. rsp->gp_state = RCU_GP_WAIT_GPS;
  15637. - wait_event_interruptible(rsp->gp_wq,
  15638. + swait_event_interruptible(rsp->gp_wq,
  15639. ACCESS_ONCE(rsp->gp_flags) &
  15640. RCU_GP_FLAG_INIT);
  15641. /* Locking provides needed memory barrier. */
  15642. @@ -2015,7 +2042,7 @@
  15643. ACCESS_ONCE(rsp->gpnum),
  15644. TPS("fqswait"));
  15645. rsp->gp_state = RCU_GP_WAIT_FQS;
  15646. - ret = wait_event_interruptible_timeout(rsp->gp_wq,
  15647. + ret = swait_event_interruptible_timeout(rsp->gp_wq,
  15648. ((gf = ACCESS_ONCE(rsp->gp_flags)) &
  15649. RCU_GP_FLAG_FQS) ||
  15650. (!ACCESS_ONCE(rnp->qsmask) &&
  15651. @@ -2860,18 +2887,17 @@
  15652. /*
  15653. * Do RCU core processing for the current CPU.
  15654. */
  15655. -static void rcu_process_callbacks(struct softirq_action *unused)
  15656. +static void rcu_process_callbacks(void)
  15657. {
  15658. struct rcu_state *rsp;
  15659. if (cpu_is_offline(smp_processor_id()))
  15660. return;
  15661. - trace_rcu_utilization(TPS("Start RCU core"));
  15662. for_each_rcu_flavor(rsp)
  15663. __rcu_process_callbacks(rsp);
  15664. - trace_rcu_utilization(TPS("End RCU core"));
  15665. }
  15666. +static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  15667. /*
  15668. * Schedule RCU callback invocation. If the specified type of RCU
  15669. * does not support RCU priority boosting, just do a direct call,
  15670. @@ -2883,18 +2909,105 @@
  15671. {
  15672. if (unlikely(!ACCESS_ONCE(rcu_scheduler_fully_active)))
  15673. return;
  15674. - if (likely(!rsp->boost)) {
  15675. - rcu_do_batch(rsp, rdp);
  15676. + rcu_do_batch(rsp, rdp);
  15677. +}
  15678. +
  15679. +static void rcu_wake_cond(struct task_struct *t, int status)
  15680. +{
  15681. + /*
  15682. + * If the thread is yielding, only wake it when this
  15683. + * is invoked from idle
  15684. + */
  15685. + if (t && (status != RCU_KTHREAD_YIELDING || is_idle_task(current)))
  15686. + wake_up_process(t);
  15687. +}
  15688. +
  15689. +/*
  15690. + * Wake up this CPU's rcuc kthread to do RCU core processing.
  15691. + */
  15692. +static void invoke_rcu_core(void)
  15693. +{
  15694. + unsigned long flags;
  15695. + struct task_struct *t;
  15696. +
  15697. + if (!cpu_online(smp_processor_id()))
  15698. return;
  15699. + local_irq_save(flags);
  15700. + __this_cpu_write(rcu_cpu_has_work, 1);
  15701. + t = __this_cpu_read(rcu_cpu_kthread_task);
  15702. + if (t != NULL && current != t)
  15703. + rcu_wake_cond(t, __this_cpu_read(rcu_cpu_kthread_status));
  15704. + local_irq_restore(flags);
  15705. +}
  15706. +
  15707. +static void rcu_cpu_kthread_park(unsigned int cpu)
  15708. +{
  15709. + per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  15710. +}
  15711. +
  15712. +static int rcu_cpu_kthread_should_run(unsigned int cpu)
  15713. +{
  15714. + return __this_cpu_read(rcu_cpu_has_work);
  15715. +}
  15716. +
  15717. +/*
  15718. + * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  15719. + * RCU softirq used in flavors and configurations of RCU that do not
  15720. + * support RCU priority boosting.
  15721. + */
  15722. +static void rcu_cpu_kthread(unsigned int cpu)
  15723. +{
  15724. + unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  15725. + char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  15726. + int spincnt;
  15727. +
  15728. + for (spincnt = 0; spincnt < 10; spincnt++) {
  15729. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  15730. + local_bh_disable();
  15731. + *statusp = RCU_KTHREAD_RUNNING;
  15732. + this_cpu_inc(rcu_cpu_kthread_loops);
  15733. + local_irq_disable();
  15734. + work = *workp;
  15735. + *workp = 0;
  15736. + local_irq_enable();
  15737. + if (work)
  15738. + rcu_process_callbacks();
  15739. + local_bh_enable();
  15740. + if (*workp == 0) {
  15741. + trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  15742. + *statusp = RCU_KTHREAD_WAITING;
  15743. + return;
  15744. + }
  15745. }
  15746. - invoke_rcu_callbacks_kthread();
  15747. + *statusp = RCU_KTHREAD_YIELDING;
  15748. + trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  15749. + schedule_timeout_interruptible(2);
  15750. + trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  15751. + *statusp = RCU_KTHREAD_WAITING;
  15752. }
  15753. -static void invoke_rcu_core(void)
  15754. +static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  15755. + .store = &rcu_cpu_kthread_task,
  15756. + .thread_should_run = rcu_cpu_kthread_should_run,
  15757. + .thread_fn = rcu_cpu_kthread,
  15758. + .thread_comm = "rcuc/%u",
  15759. + .setup = rcu_cpu_kthread_setup,
  15760. + .park = rcu_cpu_kthread_park,
  15761. +};
  15762. +
  15763. +/*
  15764. + * Spawn per-CPU RCU core processing kthreads.
  15765. + */
  15766. +static int __init rcu_spawn_core_kthreads(void)
  15767. {
  15768. - if (cpu_online(smp_processor_id()))
  15769. - raise_softirq(RCU_SOFTIRQ);
  15770. + int cpu;
  15771. +
  15772. + for_each_possible_cpu(cpu)
  15773. + per_cpu(rcu_cpu_has_work, cpu) = 0;
  15774. + BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  15775. + return 0;
  15776. }
  15777. +early_initcall(rcu_spawn_core_kthreads);
  15778. /*
  15779. * Handle any core-RCU processing required by a call_rcu() invocation.
  15780. @@ -3040,6 +3153,7 @@
  15781. }
  15782. EXPORT_SYMBOL_GPL(call_rcu_sched);
  15783. +#ifndef CONFIG_PREEMPT_RT_FULL
  15784. /*
  15785. * Queue an RCU callback for invocation after a quicker grace period.
  15786. */
  15787. @@ -3048,6 +3162,7 @@
  15788. __call_rcu(head, func, &rcu_bh_state, -1, 0);
  15789. }
  15790. EXPORT_SYMBOL_GPL(call_rcu_bh);
  15791. +#endif
  15792. /*
  15793. * Queue an RCU callback for lazy invocation after a grace period.
  15794. @@ -3139,6 +3254,7 @@
  15795. }
  15796. EXPORT_SYMBOL_GPL(synchronize_sched);
  15797. +#ifndef CONFIG_PREEMPT_RT_FULL
  15798. /**
  15799. * synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
  15800. *
  15801. @@ -3165,6 +3281,7 @@
  15802. wait_rcu_gp(call_rcu_bh);
  15803. }
  15804. EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
  15805. +#endif
  15806. /**
  15807. * get_state_synchronize_rcu - Snapshot current RCU state
  15808. @@ -3677,6 +3794,7 @@
  15809. mutex_unlock(&rsp->barrier_mutex);
  15810. }
  15811. +#ifndef CONFIG_PREEMPT_RT_FULL
  15812. /**
  15813. * rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
  15814. */
  15815. @@ -3685,6 +3803,7 @@
  15816. _rcu_barrier(&rcu_bh_state);
  15817. }
  15818. EXPORT_SYMBOL_GPL(rcu_barrier_bh);
  15819. +#endif
  15820. /**
  15821. * rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
  15822. @@ -4021,7 +4140,7 @@
  15823. }
  15824. }
  15825. - init_waitqueue_head(&rsp->gp_wq);
  15826. + init_swait_head(&rsp->gp_wq);
  15827. rnp = rsp->level[rcu_num_lvls - 1];
  15828. for_each_possible_cpu(i) {
  15829. while (i > rnp->grphi)
  15830. @@ -4120,7 +4239,6 @@
  15831. rcu_init_one(&rcu_bh_state, &rcu_bh_data);
  15832. rcu_init_one(&rcu_sched_state, &rcu_sched_data);
  15833. __rcu_init_preempt();
  15834. - open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  15835. /*
  15836. * We don't need protection against CPU-hotplug here because
  15837. diff -Nur linux-4.1.6.orig/kernel/rcu/tree.h linux-4.1.6/kernel/rcu/tree.h
  15838. --- linux-4.1.6.orig/kernel/rcu/tree.h 2015-08-17 05:52:51.000000000 +0200
  15839. +++ linux-4.1.6/kernel/rcu/tree.h 2015-09-08 23:49:08.105867384 +0200
  15840. @@ -27,6 +27,7 @@
  15841. #include <linux/threads.h>
  15842. #include <linux/cpumask.h>
  15843. #include <linux/seqlock.h>
  15844. +#include <linux/wait-simple.h>
  15845. /*
  15846. * Define shape of hierarchy based on NR_CPUS, CONFIG_RCU_FANOUT, and
  15847. @@ -210,7 +211,7 @@
  15848. /* This can happen due to race conditions. */
  15849. #endif /* #ifdef CONFIG_RCU_BOOST */
  15850. #ifdef CONFIG_RCU_NOCB_CPU
  15851. - wait_queue_head_t nocb_gp_wq[2];
  15852. + struct swait_head nocb_gp_wq[2];
  15853. /* Place for rcu_nocb_kthread() to wait GP. */
  15854. #endif /* #ifdef CONFIG_RCU_NOCB_CPU */
  15855. int need_future_gp[2];
  15856. @@ -349,7 +350,7 @@
  15857. atomic_long_t nocb_q_count_lazy; /* invocation (all stages). */
  15858. struct rcu_head *nocb_follower_head; /* CBs ready to invoke. */
  15859. struct rcu_head **nocb_follower_tail;
  15860. - wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */
  15861. + struct swait_head nocb_wq; /* For nocb kthreads to sleep on. */
  15862. struct task_struct *nocb_kthread;
  15863. int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
  15864. @@ -438,7 +439,7 @@
  15865. unsigned long gpnum; /* Current gp number. */
  15866. unsigned long completed; /* # of last completed gp. */
  15867. struct task_struct *gp_kthread; /* Task for grace periods. */
  15868. - wait_queue_head_t gp_wq; /* Where GP task waits. */
  15869. + struct swait_head gp_wq; /* Where GP task waits. */
  15870. short gp_flags; /* Commands for GP task. */
  15871. short gp_state; /* GP kthread sleep state. */
  15872. @@ -529,12 +530,10 @@
  15873. DECLARE_PER_CPU(struct rcu_data, rcu_preempt_data);
  15874. #endif /* #ifdef CONFIG_PREEMPT_RCU */
  15875. -#ifdef CONFIG_RCU_BOOST
  15876. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  15877. DECLARE_PER_CPU(int, rcu_cpu_kthread_cpu);
  15878. DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  15879. DECLARE_PER_CPU(char, rcu_cpu_has_work);
  15880. -#endif /* #ifdef CONFIG_RCU_BOOST */
  15881. #ifndef RCU_TREE_NONCORE
  15882. @@ -553,10 +552,9 @@
  15883. static void __init __rcu_init_preempt(void);
  15884. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  15885. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
  15886. -static void invoke_rcu_callbacks_kthread(void);
  15887. static bool rcu_is_callbacks_kthread(void);
  15888. +static void rcu_cpu_kthread_setup(unsigned int cpu);
  15889. #ifdef CONFIG_RCU_BOOST
  15890. -static void rcu_preempt_do_callbacks(void);
  15891. static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
  15892. struct rcu_node *rnp);
  15893. #endif /* #ifdef CONFIG_RCU_BOOST */
  15894. diff -Nur linux-4.1.6.orig/kernel/rcu/tree_plugin.h linux-4.1.6/kernel/rcu/tree_plugin.h
  15895. --- linux-4.1.6.orig/kernel/rcu/tree_plugin.h 2015-08-17 05:52:51.000000000 +0200
  15896. +++ linux-4.1.6/kernel/rcu/tree_plugin.h 2015-09-08 23:49:08.105867384 +0200
  15897. @@ -24,27 +24,20 @@
  15898. * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  15899. */
  15900. -#include <linux/delay.h>
  15901. -#include <linux/gfp.h>
  15902. -#include <linux/oom.h>
  15903. -#include <linux/smpboot.h>
  15904. -#include "../time/tick-internal.h"
  15905. -
  15906. #ifdef CONFIG_RCU_BOOST
  15907. #include "../locking/rtmutex_common.h"
  15908. +#endif /* #ifdef CONFIG_RCU_BOOST */
  15909. +
  15910. /*
  15911. * Control variables for per-CPU and per-rcu_node kthreads. These
  15912. * handle all flavors of RCU.
  15913. */
  15914. -static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
  15915. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
  15916. DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
  15917. DEFINE_PER_CPU(char, rcu_cpu_has_work);
  15918. -#endif /* #ifdef CONFIG_RCU_BOOST */
  15919. -
  15920. #ifdef CONFIG_RCU_NOCB_CPU
  15921. static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
  15922. static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */
  15923. @@ -291,7 +284,7 @@
  15924. }
  15925. /* Hardware IRQ handlers cannot block, complain if they get here. */
  15926. - if (in_irq() || in_serving_softirq()) {
  15927. + if (preempt_count() & (HARDIRQ_MASK | SOFTIRQ_OFFSET)) {
  15928. lockdep_rcu_suspicious(__FILE__, __LINE__,
  15929. "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n");
  15930. pr_alert("->rcu_read_unlock_special: %#x (b: %d, nq: %d)\n",
  15931. @@ -496,15 +489,6 @@
  15932. t->rcu_read_unlock_special.b.need_qs = true;
  15933. }
  15934. -#ifdef CONFIG_RCU_BOOST
  15935. -
  15936. -static void rcu_preempt_do_callbacks(void)
  15937. -{
  15938. - rcu_do_batch(&rcu_preempt_state, this_cpu_ptr(&rcu_preempt_data));
  15939. -}
  15940. -
  15941. -#endif /* #ifdef CONFIG_RCU_BOOST */
  15942. -
  15943. /*
  15944. * Queue a preemptible-RCU callback for invocation after a grace period.
  15945. */
  15946. @@ -939,6 +923,19 @@
  15947. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  15948. +/*
  15949. + * If boosting, set rcuc kthreads to realtime priority.
  15950. + */
  15951. +static void rcu_cpu_kthread_setup(unsigned int cpu)
  15952. +{
  15953. +#ifdef CONFIG_RCU_BOOST
  15954. + struct sched_param sp;
  15955. +
  15956. + sp.sched_priority = kthread_prio;
  15957. + sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  15958. +#endif /* #ifdef CONFIG_RCU_BOOST */
  15959. +}
  15960. +
  15961. #ifdef CONFIG_RCU_BOOST
  15962. #include "../locking/rtmutex_common.h"
  15963. @@ -970,16 +967,6 @@
  15964. #endif /* #else #ifdef CONFIG_RCU_TRACE */
  15965. -static void rcu_wake_cond(struct task_struct *t, int status)
  15966. -{
  15967. - /*
  15968. - * If the thread is yielding, only wake it when this
  15969. - * is invoked from idle
  15970. - */
  15971. - if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
  15972. - wake_up_process(t);
  15973. -}
  15974. -
  15975. /*
  15976. * Carry out RCU priority boosting on the task indicated by ->exp_tasks
  15977. * or ->boost_tasks, advancing the pointer to the next task in the
  15978. @@ -1125,23 +1112,6 @@
  15979. }
  15980. /*
  15981. - * Wake up the per-CPU kthread to invoke RCU callbacks.
  15982. - */
  15983. -static void invoke_rcu_callbacks_kthread(void)
  15984. -{
  15985. - unsigned long flags;
  15986. -
  15987. - local_irq_save(flags);
  15988. - __this_cpu_write(rcu_cpu_has_work, 1);
  15989. - if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
  15990. - current != __this_cpu_read(rcu_cpu_kthread_task)) {
  15991. - rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
  15992. - __this_cpu_read(rcu_cpu_kthread_status));
  15993. - }
  15994. - local_irq_restore(flags);
  15995. -}
  15996. -
  15997. -/*
  15998. * Is the current CPU running the RCU-callbacks kthread?
  15999. * Caller must have preemption disabled.
  16000. */
  16001. @@ -1196,67 +1166,6 @@
  16002. return 0;
  16003. }
  16004. -static void rcu_kthread_do_work(void)
  16005. -{
  16006. - rcu_do_batch(&rcu_sched_state, this_cpu_ptr(&rcu_sched_data));
  16007. - rcu_do_batch(&rcu_bh_state, this_cpu_ptr(&rcu_bh_data));
  16008. - rcu_preempt_do_callbacks();
  16009. -}
  16010. -
  16011. -static void rcu_cpu_kthread_setup(unsigned int cpu)
  16012. -{
  16013. - struct sched_param sp;
  16014. -
  16015. - sp.sched_priority = kthread_prio;
  16016. - sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
  16017. -}
  16018. -
  16019. -static void rcu_cpu_kthread_park(unsigned int cpu)
  16020. -{
  16021. - per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
  16022. -}
  16023. -
  16024. -static int rcu_cpu_kthread_should_run(unsigned int cpu)
  16025. -{
  16026. - return __this_cpu_read(rcu_cpu_has_work);
  16027. -}
  16028. -
  16029. -/*
  16030. - * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
  16031. - * RCU softirq used in flavors and configurations of RCU that do not
  16032. - * support RCU priority boosting.
  16033. - */
  16034. -static void rcu_cpu_kthread(unsigned int cpu)
  16035. -{
  16036. - unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
  16037. - char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
  16038. - int spincnt;
  16039. -
  16040. - for (spincnt = 0; spincnt < 10; spincnt++) {
  16041. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
  16042. - local_bh_disable();
  16043. - *statusp = RCU_KTHREAD_RUNNING;
  16044. - this_cpu_inc(rcu_cpu_kthread_loops);
  16045. - local_irq_disable();
  16046. - work = *workp;
  16047. - *workp = 0;
  16048. - local_irq_enable();
  16049. - if (work)
  16050. - rcu_kthread_do_work();
  16051. - local_bh_enable();
  16052. - if (*workp == 0) {
  16053. - trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
  16054. - *statusp = RCU_KTHREAD_WAITING;
  16055. - return;
  16056. - }
  16057. - }
  16058. - *statusp = RCU_KTHREAD_YIELDING;
  16059. - trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
  16060. - schedule_timeout_interruptible(2);
  16061. - trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
  16062. - *statusp = RCU_KTHREAD_WAITING;
  16063. -}
  16064. -
  16065. /*
  16066. * Set the per-rcu_node kthread's affinity to cover all CPUs that are
  16067. * served by the rcu_node in question. The CPU hotplug lock is still
  16068. @@ -1286,26 +1195,12 @@
  16069. free_cpumask_var(cm);
  16070. }
  16071. -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
  16072. - .store = &rcu_cpu_kthread_task,
  16073. - .thread_should_run = rcu_cpu_kthread_should_run,
  16074. - .thread_fn = rcu_cpu_kthread,
  16075. - .thread_comm = "rcuc/%u",
  16076. - .setup = rcu_cpu_kthread_setup,
  16077. - .park = rcu_cpu_kthread_park,
  16078. -};
  16079. -
  16080. /*
  16081. * Spawn boost kthreads -- called as soon as the scheduler is running.
  16082. */
  16083. static void __init rcu_spawn_boost_kthreads(void)
  16084. {
  16085. struct rcu_node *rnp;
  16086. - int cpu;
  16087. -
  16088. - for_each_possible_cpu(cpu)
  16089. - per_cpu(rcu_cpu_has_work, cpu) = 0;
  16090. - BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
  16091. rcu_for_each_leaf_node(rcu_state_p, rnp)
  16092. (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
  16093. }
  16094. @@ -1328,11 +1223,6 @@
  16095. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  16096. }
  16097. -static void invoke_rcu_callbacks_kthread(void)
  16098. -{
  16099. - WARN_ON_ONCE(1);
  16100. -}
  16101. -
  16102. static bool rcu_is_callbacks_kthread(void)
  16103. {
  16104. return false;
  16105. @@ -1356,7 +1246,7 @@
  16106. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  16107. -#if !defined(CONFIG_RCU_FAST_NO_HZ)
  16108. +#if !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL)
  16109. /*
  16110. * Check to see if any future RCU-related work will need to be done
  16111. @@ -1374,7 +1264,9 @@
  16112. return rcu_cpu_has_callbacks(NULL);
  16113. }
  16114. #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
  16115. +#endif /* !defined(CONFIG_RCU_FAST_NO_HZ) || defined(CONFIG_PREEMPT_RT_FULL) */
  16116. +#if !defined(CONFIG_RCU_FAST_NO_HZ)
  16117. /*
  16118. * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
  16119. * after it.
  16120. @@ -1472,6 +1364,8 @@
  16121. return cbs_ready;
  16122. }
  16123. +#ifndef CONFIG_PREEMPT_RT_FULL
  16124. +
  16125. /*
  16126. * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
  16127. * to invoke. If the CPU has callbacks, try to advance them. Tell the
  16128. @@ -1512,7 +1406,7 @@
  16129. return 0;
  16130. }
  16131. #endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
  16132. -
  16133. +#endif /* #ifndef CONFIG_PREEMPT_RT_FULL */
  16134. /*
  16135. * Prepare a CPU for idle from an RCU perspective. The first major task
  16136. * is to sense whether nohz mode has been enabled or disabled via sysfs.
  16137. @@ -1859,7 +1753,7 @@
  16138. */
  16139. static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
  16140. {
  16141. - wake_up_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
  16142. + swait_wake_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
  16143. }
  16144. /*
  16145. @@ -1877,8 +1771,8 @@
  16146. static void rcu_init_one_nocb(struct rcu_node *rnp)
  16147. {
  16148. - init_waitqueue_head(&rnp->nocb_gp_wq[0]);
  16149. - init_waitqueue_head(&rnp->nocb_gp_wq[1]);
  16150. + init_swait_head(&rnp->nocb_gp_wq[0]);
  16151. + init_swait_head(&rnp->nocb_gp_wq[1]);
  16152. }
  16153. #ifndef CONFIG_RCU_NOCB_CPU_ALL
  16154. @@ -1903,7 +1797,7 @@
  16155. if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
  16156. /* Prior smp_mb__after_atomic() orders against prior enqueue. */
  16157. ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
  16158. - wake_up(&rdp_leader->nocb_wq);
  16159. + swait_wake(&rdp_leader->nocb_wq);
  16160. }
  16161. }
  16162. @@ -2116,7 +2010,7 @@
  16163. */
  16164. trace_rcu_future_gp(rnp, rdp, c, TPS("StartWait"));
  16165. for (;;) {
  16166. - wait_event_interruptible(
  16167. + swait_event_interruptible(
  16168. rnp->nocb_gp_wq[c & 0x1],
  16169. (d = ULONG_CMP_GE(ACCESS_ONCE(rnp->completed), c)));
  16170. if (likely(d))
  16171. @@ -2144,7 +2038,7 @@
  16172. /* Wait for callbacks to appear. */
  16173. if (!rcu_nocb_poll) {
  16174. trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep");
  16175. - wait_event_interruptible(my_rdp->nocb_wq,
  16176. + swait_event_interruptible(my_rdp->nocb_wq,
  16177. !ACCESS_ONCE(my_rdp->nocb_leader_sleep));
  16178. /* Memory barrier handled by smp_mb() calls below and repoll. */
  16179. } else if (firsttime) {
  16180. @@ -2219,7 +2113,7 @@
  16181. * List was empty, wake up the follower.
  16182. * Memory barriers supplied by atomic_long_add().
  16183. */
  16184. - wake_up(&rdp->nocb_wq);
  16185. + swait_wake(&rdp->nocb_wq);
  16186. }
  16187. }
  16188. @@ -2240,7 +2134,7 @@
  16189. if (!rcu_nocb_poll) {
  16190. trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
  16191. "FollowerSleep");
  16192. - wait_event_interruptible(rdp->nocb_wq,
  16193. + swait_event_interruptible(rdp->nocb_wq,
  16194. ACCESS_ONCE(rdp->nocb_follower_head));
  16195. } else if (firsttime) {
  16196. /* Don't drown trace log with "Poll"! */
  16197. @@ -2399,7 +2293,7 @@
  16198. static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
  16199. {
  16200. rdp->nocb_tail = &rdp->nocb_head;
  16201. - init_waitqueue_head(&rdp->nocb_wq);
  16202. + init_swait_head(&rdp->nocb_wq);
  16203. rdp->nocb_follower_tail = &rdp->nocb_follower_head;
  16204. }
  16205. diff -Nur linux-4.1.6.orig/kernel/rcu/update.c linux-4.1.6/kernel/rcu/update.c
  16206. --- linux-4.1.6.orig/kernel/rcu/update.c 2015-08-17 05:52:51.000000000 +0200
  16207. +++ linux-4.1.6/kernel/rcu/update.c 2015-09-08 23:49:08.105867384 +0200
  16208. @@ -227,6 +227,7 @@
  16209. }
  16210. EXPORT_SYMBOL_GPL(rcu_read_lock_held);
  16211. +#ifndef CONFIG_PREEMPT_RT_FULL
  16212. /**
  16213. * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
  16214. *
  16215. @@ -253,6 +254,7 @@
  16216. return in_softirq() || irqs_disabled();
  16217. }
  16218. EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
  16219. +#endif
  16220. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  16221. diff -Nur linux-4.1.6.orig/kernel/relay.c linux-4.1.6/kernel/relay.c
  16222. --- linux-4.1.6.orig/kernel/relay.c 2015-08-17 05:52:51.000000000 +0200
  16223. +++ linux-4.1.6/kernel/relay.c 2015-09-08 23:49:08.105867384 +0200
  16224. @@ -339,6 +339,10 @@
  16225. {
  16226. struct rchan_buf *buf = (struct rchan_buf *)data;
  16227. wake_up_interruptible(&buf->read_wait);
  16228. + /*
  16229. + * Stupid polling for now:
  16230. + */
  16231. + mod_timer(&buf->timer, jiffies + 1);
  16232. }
  16233. /**
  16234. @@ -356,6 +360,7 @@
  16235. init_waitqueue_head(&buf->read_wait);
  16236. kref_init(&buf->kref);
  16237. setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
  16238. + mod_timer(&buf->timer, jiffies + 1);
  16239. } else
  16240. del_timer_sync(&buf->timer);
  16241. @@ -739,15 +744,6 @@
  16242. else
  16243. buf->early_bytes += buf->chan->subbuf_size -
  16244. buf->padding[old_subbuf];
  16245. - smp_mb();
  16246. - if (waitqueue_active(&buf->read_wait))
  16247. - /*
  16248. - * Calling wake_up_interruptible() from here
  16249. - * will deadlock if we happen to be logging
  16250. - * from the scheduler (trying to re-grab
  16251. - * rq->lock), so defer it.
  16252. - */
  16253. - mod_timer(&buf->timer, jiffies + 1);
  16254. }
  16255. old = buf->data;
  16256. diff -Nur linux-4.1.6.orig/kernel/sched/completion.c linux-4.1.6/kernel/sched/completion.c
  16257. --- linux-4.1.6.orig/kernel/sched/completion.c 2015-08-17 05:52:51.000000000 +0200
  16258. +++ linux-4.1.6/kernel/sched/completion.c 2015-09-08 23:49:08.105867384 +0200
  16259. @@ -30,10 +30,10 @@
  16260. {
  16261. unsigned long flags;
  16262. - spin_lock_irqsave(&x->wait.lock, flags);
  16263. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  16264. x->done++;
  16265. - __wake_up_locked(&x->wait, TASK_NORMAL, 1);
  16266. - spin_unlock_irqrestore(&x->wait.lock, flags);
  16267. + __swait_wake_locked(&x->wait, TASK_NORMAL, 1);
  16268. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  16269. }
  16270. EXPORT_SYMBOL(complete);
  16271. @@ -50,10 +50,10 @@
  16272. {
  16273. unsigned long flags;
  16274. - spin_lock_irqsave(&x->wait.lock, flags);
  16275. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  16276. x->done += UINT_MAX/2;
  16277. - __wake_up_locked(&x->wait, TASK_NORMAL, 0);
  16278. - spin_unlock_irqrestore(&x->wait.lock, flags);
  16279. + __swait_wake_locked(&x->wait, TASK_NORMAL, 0);
  16280. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  16281. }
  16282. EXPORT_SYMBOL(complete_all);
  16283. @@ -62,20 +62,20 @@
  16284. long (*action)(long), long timeout, int state)
  16285. {
  16286. if (!x->done) {
  16287. - DECLARE_WAITQUEUE(wait, current);
  16288. + DEFINE_SWAITER(wait);
  16289. - __add_wait_queue_tail_exclusive(&x->wait, &wait);
  16290. + swait_prepare_locked(&x->wait, &wait);
  16291. do {
  16292. if (signal_pending_state(state, current)) {
  16293. timeout = -ERESTARTSYS;
  16294. break;
  16295. }
  16296. __set_current_state(state);
  16297. - spin_unlock_irq(&x->wait.lock);
  16298. + raw_spin_unlock_irq(&x->wait.lock);
  16299. timeout = action(timeout);
  16300. - spin_lock_irq(&x->wait.lock);
  16301. + raw_spin_lock_irq(&x->wait.lock);
  16302. } while (!x->done && timeout);
  16303. - __remove_wait_queue(&x->wait, &wait);
  16304. + swait_finish_locked(&x->wait, &wait);
  16305. if (!x->done)
  16306. return timeout;
  16307. }
  16308. @@ -89,9 +89,9 @@
  16309. {
  16310. might_sleep();
  16311. - spin_lock_irq(&x->wait.lock);
  16312. + raw_spin_lock_irq(&x->wait.lock);
  16313. timeout = do_wait_for_common(x, action, timeout, state);
  16314. - spin_unlock_irq(&x->wait.lock);
  16315. + raw_spin_unlock_irq(&x->wait.lock);
  16316. return timeout;
  16317. }
  16318. @@ -277,12 +277,12 @@
  16319. if (!READ_ONCE(x->done))
  16320. return 0;
  16321. - spin_lock_irqsave(&x->wait.lock, flags);
  16322. + raw_spin_lock_irqsave(&x->wait.lock, flags);
  16323. if (!x->done)
  16324. ret = 0;
  16325. else
  16326. x->done--;
  16327. - spin_unlock_irqrestore(&x->wait.lock, flags);
  16328. + raw_spin_unlock_irqrestore(&x->wait.lock, flags);
  16329. return ret;
  16330. }
  16331. EXPORT_SYMBOL(try_wait_for_completion);
  16332. @@ -311,7 +311,7 @@
  16333. * after it's acquired the lock.
  16334. */
  16335. smp_rmb();
  16336. - spin_unlock_wait(&x->wait.lock);
  16337. + raw_spin_unlock_wait(&x->wait.lock);
  16338. return true;
  16339. }
  16340. EXPORT_SYMBOL(completion_done);
  16341. diff -Nur linux-4.1.6.orig/kernel/sched/core.c linux-4.1.6/kernel/sched/core.c
  16342. --- linux-4.1.6.orig/kernel/sched/core.c 2015-08-17 05:52:51.000000000 +0200
  16343. +++ linux-4.1.6/kernel/sched/core.c 2015-09-08 23:49:08.109866942 +0200
  16344. @@ -282,7 +282,11 @@
  16345. * Number of tasks to iterate in a single balance run.
  16346. * Limited because this is done with IRQs disabled.
  16347. */
  16348. +#ifndef CONFIG_PREEMPT_RT_FULL
  16349. const_debug unsigned int sysctl_sched_nr_migrate = 32;
  16350. +#else
  16351. +const_debug unsigned int sysctl_sched_nr_migrate = 8;
  16352. +#endif
  16353. /*
  16354. * period over which we average the RT time consumption, measured
  16355. @@ -461,6 +465,7 @@
  16356. hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  16357. rq->hrtick_timer.function = hrtick;
  16358. + rq->hrtick_timer.irqsafe = 1;
  16359. }
  16360. #else /* CONFIG_SCHED_HRTICK */
  16361. static inline void hrtick_clear(struct rq *rq)
  16362. @@ -541,6 +546,52 @@
  16363. #endif
  16364. #endif
  16365. +void wake_q_add(struct wake_q_head *head, struct task_struct *task)
  16366. +{
  16367. + struct wake_q_node *node = &task->wake_q;
  16368. +
  16369. + /*
  16370. + * Atomically grab the task, if ->wake_q is !nil already it means
  16371. + * its already queued (either by us or someone else) and will get the
  16372. + * wakeup due to that.
  16373. + *
  16374. + * This cmpxchg() implies a full barrier, which pairs with the write
  16375. + * barrier implied by the wakeup in wake_up_list().
  16376. + */
  16377. + if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL))
  16378. + return;
  16379. +
  16380. + get_task_struct(task);
  16381. +
  16382. + /*
  16383. + * The head is context local, there can be no concurrency.
  16384. + */
  16385. + *head->lastp = node;
  16386. + head->lastp = &node->next;
  16387. +}
  16388. +
  16389. +void wake_up_q(struct wake_q_head *head)
  16390. +{
  16391. + struct wake_q_node *node = head->first;
  16392. +
  16393. + while (node != WAKE_Q_TAIL) {
  16394. + struct task_struct *task;
  16395. +
  16396. + task = container_of(node, struct task_struct, wake_q);
  16397. + BUG_ON(!task);
  16398. + /* task can safely be re-inserted now */
  16399. + node = node->next;
  16400. + task->wake_q.next = NULL;
  16401. +
  16402. + /*
  16403. + * wake_up_process() implies a wmb() to pair with the queueing
  16404. + * in wake_q_add() so as not to miss wakeups.
  16405. + */
  16406. + wake_up_process(task);
  16407. + put_task_struct(task);
  16408. + }
  16409. +}
  16410. +
  16411. /*
  16412. * resched_curr - mark rq's current task 'to be rescheduled now'.
  16413. *
  16414. @@ -572,6 +623,38 @@
  16415. trace_sched_wake_idle_without_ipi(cpu);
  16416. }
  16417. +#ifdef CONFIG_PREEMPT_LAZY
  16418. +void resched_curr_lazy(struct rq *rq)
  16419. +{
  16420. + struct task_struct *curr = rq->curr;
  16421. + int cpu;
  16422. +
  16423. + if (!sched_feat(PREEMPT_LAZY)) {
  16424. + resched_curr(rq);
  16425. + return;
  16426. + }
  16427. +
  16428. + lockdep_assert_held(&rq->lock);
  16429. +
  16430. + if (test_tsk_need_resched(curr))
  16431. + return;
  16432. +
  16433. + if (test_tsk_need_resched_lazy(curr))
  16434. + return;
  16435. +
  16436. + set_tsk_need_resched_lazy(curr);
  16437. +
  16438. + cpu = cpu_of(rq);
  16439. + if (cpu == smp_processor_id())
  16440. + return;
  16441. +
  16442. + /* NEED_RESCHED_LAZY must be visible before we test polling */
  16443. + smp_mb();
  16444. + if (!tsk_is_polling(curr))
  16445. + smp_send_reschedule(cpu);
  16446. +}
  16447. +#endif
  16448. +
  16449. void resched_cpu(int cpu)
  16450. {
  16451. struct rq *rq = cpu_rq(cpu);
  16452. @@ -595,12 +678,14 @@
  16453. */
  16454. int get_nohz_timer_target(int pinned)
  16455. {
  16456. - int cpu = smp_processor_id();
  16457. + int cpu;
  16458. int i;
  16459. struct sched_domain *sd;
  16460. + preempt_disable_rt();
  16461. + cpu = smp_processor_id();
  16462. if (pinned || !get_sysctl_timer_migration() || !idle_cpu(cpu))
  16463. - return cpu;
  16464. + goto preempt_en_rt;
  16465. rcu_read_lock();
  16466. for_each_domain(cpu, sd) {
  16467. @@ -613,6 +698,8 @@
  16468. }
  16469. unlock:
  16470. rcu_read_unlock();
  16471. +preempt_en_rt:
  16472. + preempt_enable_rt();
  16473. return cpu;
  16474. }
  16475. /*
  16476. @@ -1164,6 +1251,18 @@
  16477. static int migration_cpu_stop(void *data);
  16478. +static bool check_task_state(struct task_struct *p, long match_state)
  16479. +{
  16480. + bool match = false;
  16481. +
  16482. + raw_spin_lock_irq(&p->pi_lock);
  16483. + if (p->state == match_state || p->saved_state == match_state)
  16484. + match = true;
  16485. + raw_spin_unlock_irq(&p->pi_lock);
  16486. +
  16487. + return match;
  16488. +}
  16489. +
  16490. /*
  16491. * wait_task_inactive - wait for a thread to unschedule.
  16492. *
  16493. @@ -1208,7 +1307,7 @@
  16494. * is actually now running somewhere else!
  16495. */
  16496. while (task_running(rq, p)) {
  16497. - if (match_state && unlikely(p->state != match_state))
  16498. + if (match_state && !check_task_state(p, match_state))
  16499. return 0;
  16500. cpu_relax();
  16501. }
  16502. @@ -1223,7 +1322,8 @@
  16503. running = task_running(rq, p);
  16504. queued = task_on_rq_queued(p);
  16505. ncsw = 0;
  16506. - if (!match_state || p->state == match_state)
  16507. + if (!match_state || p->state == match_state ||
  16508. + p->saved_state == match_state)
  16509. ncsw = p->nvcsw | LONG_MIN; /* sets MSB */
  16510. task_rq_unlock(rq, p, &flags);
  16511. @@ -1449,10 +1549,6 @@
  16512. {
  16513. activate_task(rq, p, en_flags);
  16514. p->on_rq = TASK_ON_RQ_QUEUED;
  16515. -
  16516. - /* if a worker is waking up, notify workqueue */
  16517. - if (p->flags & PF_WQ_WORKER)
  16518. - wq_worker_waking_up(p, cpu_of(rq));
  16519. }
  16520. /*
  16521. @@ -1666,8 +1762,27 @@
  16522. */
  16523. smp_mb__before_spinlock();
  16524. raw_spin_lock_irqsave(&p->pi_lock, flags);
  16525. - if (!(p->state & state))
  16526. + if (!(p->state & state)) {
  16527. + /*
  16528. + * The task might be running due to a spinlock sleeper
  16529. + * wakeup. Check the saved state and set it to running
  16530. + * if the wakeup condition is true.
  16531. + */
  16532. + if (!(wake_flags & WF_LOCK_SLEEPER)) {
  16533. + if (p->saved_state & state) {
  16534. + p->saved_state = TASK_RUNNING;
  16535. + success = 1;
  16536. + }
  16537. + }
  16538. goto out;
  16539. + }
  16540. +
  16541. + /*
  16542. + * If this is a regular wakeup, then we can unconditionally
  16543. + * clear the saved state of a "lock sleeper".
  16544. + */
  16545. + if (!(wake_flags & WF_LOCK_SLEEPER))
  16546. + p->saved_state = TASK_RUNNING;
  16547. success = 1; /* we're going to change ->state */
  16548. cpu = task_cpu(p);
  16549. @@ -1710,42 +1825,6 @@
  16550. }
  16551. /**
  16552. - * try_to_wake_up_local - try to wake up a local task with rq lock held
  16553. - * @p: the thread to be awakened
  16554. - *
  16555. - * Put @p on the run-queue if it's not already there. The caller must
  16556. - * ensure that this_rq() is locked, @p is bound to this_rq() and not
  16557. - * the current task.
  16558. - */
  16559. -static void try_to_wake_up_local(struct task_struct *p)
  16560. -{
  16561. - struct rq *rq = task_rq(p);
  16562. -
  16563. - if (WARN_ON_ONCE(rq != this_rq()) ||
  16564. - WARN_ON_ONCE(p == current))
  16565. - return;
  16566. -
  16567. - lockdep_assert_held(&rq->lock);
  16568. -
  16569. - if (!raw_spin_trylock(&p->pi_lock)) {
  16570. - raw_spin_unlock(&rq->lock);
  16571. - raw_spin_lock(&p->pi_lock);
  16572. - raw_spin_lock(&rq->lock);
  16573. - }
  16574. -
  16575. - if (!(p->state & TASK_NORMAL))
  16576. - goto out;
  16577. -
  16578. - if (!task_on_rq_queued(p))
  16579. - ttwu_activate(rq, p, ENQUEUE_WAKEUP);
  16580. -
  16581. - ttwu_do_wakeup(rq, p, 0);
  16582. - ttwu_stat(p, smp_processor_id(), 0);
  16583. -out:
  16584. - raw_spin_unlock(&p->pi_lock);
  16585. -}
  16586. -
  16587. -/**
  16588. * wake_up_process - Wake up a specific process
  16589. * @p: The process to be woken up.
  16590. *
  16591. @@ -1759,11 +1838,23 @@
  16592. */
  16593. int wake_up_process(struct task_struct *p)
  16594. {
  16595. - WARN_ON(task_is_stopped_or_traced(p));
  16596. + WARN_ON(__task_is_stopped_or_traced(p));
  16597. return try_to_wake_up(p, TASK_NORMAL, 0);
  16598. }
  16599. EXPORT_SYMBOL(wake_up_process);
  16600. +/**
  16601. + * wake_up_lock_sleeper - Wake up a specific process blocked on a "sleeping lock"
  16602. + * @p: The process to be woken up.
  16603. + *
  16604. + * Same as wake_up_process() above, but wake_flags=WF_LOCK_SLEEPER to indicate
  16605. + * the nature of the wakeup.
  16606. + */
  16607. +int wake_up_lock_sleeper(struct task_struct *p)
  16608. +{
  16609. + return try_to_wake_up(p, TASK_ALL, WF_LOCK_SLEEPER);
  16610. +}
  16611. +
  16612. int wake_up_state(struct task_struct *p, unsigned int state)
  16613. {
  16614. return try_to_wake_up(p, state, 0);
  16615. @@ -1959,6 +2050,9 @@
  16616. p->on_cpu = 0;
  16617. #endif
  16618. init_task_preempt_count(p);
  16619. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  16620. + task_thread_info(p)->preempt_lazy_count = 0;
  16621. +#endif
  16622. #ifdef CONFIG_SMP
  16623. plist_node_init(&p->pushable_tasks, MAX_PRIO);
  16624. RB_CLEAR_NODE(&p->pushable_dl_tasks);
  16625. @@ -2231,8 +2325,12 @@
  16626. finish_arch_post_lock_switch();
  16627. fire_sched_in_preempt_notifiers(current);
  16628. + /*
  16629. + * We use mmdrop_delayed() here so we don't have to do the
  16630. + * full __mmdrop() when we are the last user.
  16631. + */
  16632. if (mm)
  16633. - mmdrop(mm);
  16634. + mmdrop_delayed(mm);
  16635. if (unlikely(prev_state == TASK_DEAD)) {
  16636. if (prev->sched_class->task_dead)
  16637. prev->sched_class->task_dead(prev);
  16638. @@ -2650,6 +2748,133 @@
  16639. schedstat_inc(this_rq(), sched_count);
  16640. }
  16641. +#if defined(CONFIG_PREEMPT_RT_FULL) && defined(CONFIG_SMP)
  16642. +#define MIGRATE_DISABLE_SET_AFFIN (1<<30) /* Can't make a negative */
  16643. +#define migrate_disabled_updated(p) ((p)->migrate_disable & MIGRATE_DISABLE_SET_AFFIN)
  16644. +#define migrate_disable_count(p) ((p)->migrate_disable & ~MIGRATE_DISABLE_SET_AFFIN)
  16645. +
  16646. +static inline void update_migrate_disable(struct task_struct *p)
  16647. +{
  16648. + const struct cpumask *mask;
  16649. +
  16650. + if (likely(!p->migrate_disable))
  16651. + return;
  16652. +
  16653. + /* Did we already update affinity? */
  16654. + if (unlikely(migrate_disabled_updated(p)))
  16655. + return;
  16656. +
  16657. + /*
  16658. + * Since this is always current we can get away with only locking
  16659. + * rq->lock, the ->cpus_allowed value can normally only be changed
  16660. + * while holding both p->pi_lock and rq->lock, but seeing that this
  16661. + * is current, we cannot actually be waking up, so all code that
  16662. + * relies on serialization against p->pi_lock is out of scope.
  16663. + *
  16664. + * Having rq->lock serializes us against things like
  16665. + * set_cpus_allowed_ptr() that can still happen concurrently.
  16666. + */
  16667. + mask = tsk_cpus_allowed(p);
  16668. +
  16669. + if (p->sched_class->set_cpus_allowed)
  16670. + p->sched_class->set_cpus_allowed(p, mask);
  16671. + /* mask==cpumask_of(task_cpu(p)) which has a cpumask_weight==1 */
  16672. + p->nr_cpus_allowed = 1;
  16673. +
  16674. + /* Let migrate_enable know to fix things back up */
  16675. + p->migrate_disable |= MIGRATE_DISABLE_SET_AFFIN;
  16676. +}
  16677. +
  16678. +void migrate_disable(void)
  16679. +{
  16680. + struct task_struct *p = current;
  16681. +
  16682. + if (in_atomic()) {
  16683. +#ifdef CONFIG_SCHED_DEBUG
  16684. + p->migrate_disable_atomic++;
  16685. +#endif
  16686. + return;
  16687. + }
  16688. +
  16689. +#ifdef CONFIG_SCHED_DEBUG
  16690. + if (unlikely(p->migrate_disable_atomic)) {
  16691. + tracing_off();
  16692. + WARN_ON_ONCE(1);
  16693. + }
  16694. +#endif
  16695. +
  16696. + if (p->migrate_disable) {
  16697. + p->migrate_disable++;
  16698. + return;
  16699. + }
  16700. +
  16701. + preempt_disable();
  16702. + preempt_lazy_disable();
  16703. + pin_current_cpu();
  16704. + p->migrate_disable = 1;
  16705. + preempt_enable();
  16706. +}
  16707. +EXPORT_SYMBOL(migrate_disable);
  16708. +
  16709. +void migrate_enable(void)
  16710. +{
  16711. + struct task_struct *p = current;
  16712. + const struct cpumask *mask;
  16713. + unsigned long flags;
  16714. + struct rq *rq;
  16715. +
  16716. + if (in_atomic()) {
  16717. +#ifdef CONFIG_SCHED_DEBUG
  16718. + p->migrate_disable_atomic--;
  16719. +#endif
  16720. + return;
  16721. + }
  16722. +
  16723. +#ifdef CONFIG_SCHED_DEBUG
  16724. + if (unlikely(p->migrate_disable_atomic)) {
  16725. + tracing_off();
  16726. + WARN_ON_ONCE(1);
  16727. + }
  16728. +#endif
  16729. + WARN_ON_ONCE(p->migrate_disable <= 0);
  16730. +
  16731. + if (migrate_disable_count(p) > 1) {
  16732. + p->migrate_disable--;
  16733. + return;
  16734. + }
  16735. +
  16736. + preempt_disable();
  16737. + if (unlikely(migrate_disabled_updated(p))) {
  16738. + /*
  16739. + * Undo whatever update_migrate_disable() did, also see there
  16740. + * about locking.
  16741. + */
  16742. + rq = this_rq();
  16743. + raw_spin_lock_irqsave(&rq->lock, flags);
  16744. +
  16745. + /*
  16746. + * Clearing migrate_disable causes tsk_cpus_allowed to
  16747. + * show the tasks original cpu affinity.
  16748. + */
  16749. + p->migrate_disable = 0;
  16750. + mask = tsk_cpus_allowed(p);
  16751. + if (p->sched_class->set_cpus_allowed)
  16752. + p->sched_class->set_cpus_allowed(p, mask);
  16753. + p->nr_cpus_allowed = cpumask_weight(mask);
  16754. + raw_spin_unlock_irqrestore(&rq->lock, flags);
  16755. + } else
  16756. + p->migrate_disable = 0;
  16757. +
  16758. + unpin_current_cpu();
  16759. + preempt_enable();
  16760. + preempt_lazy_enable();
  16761. +}
  16762. +EXPORT_SYMBOL(migrate_enable);
  16763. +#else
  16764. +static inline void update_migrate_disable(struct task_struct *p) { }
  16765. +#define migrate_disabled_updated(p) 0
  16766. +#endif
  16767. +
  16768. /*
  16769. * Pick up the highest-prio task:
  16770. */
  16771. @@ -2756,6 +2981,8 @@
  16772. smp_mb__before_spinlock();
  16773. raw_spin_lock_irq(&rq->lock);
  16774. + update_migrate_disable(prev);
  16775. +
  16776. rq->clock_skip_update <<= 1; /* promote REQ to ACT */
  16777. switch_count = &prev->nivcsw;
  16778. @@ -2765,19 +2992,6 @@
  16779. } else {
  16780. deactivate_task(rq, prev, DEQUEUE_SLEEP);
  16781. prev->on_rq = 0;
  16782. -
  16783. - /*
  16784. - * If a worker went to sleep, notify and ask workqueue
  16785. - * whether it wants to wake up a task to maintain
  16786. - * concurrency.
  16787. - */
  16788. - if (prev->flags & PF_WQ_WORKER) {
  16789. - struct task_struct *to_wakeup;
  16790. -
  16791. - to_wakeup = wq_worker_sleeping(prev, cpu);
  16792. - if (to_wakeup)
  16793. - try_to_wake_up_local(to_wakeup);
  16794. - }
  16795. }
  16796. switch_count = &prev->nvcsw;
  16797. }
  16798. @@ -2787,6 +3001,7 @@
  16799. next = pick_next_task(rq, prev);
  16800. clear_tsk_need_resched(prev);
  16801. + clear_tsk_need_resched_lazy(prev);
  16802. clear_preempt_need_resched();
  16803. rq->clock_skip_update = 0;
  16804. @@ -2807,8 +3022,19 @@
  16805. static inline void sched_submit_work(struct task_struct *tsk)
  16806. {
  16807. - if (!tsk->state || tsk_is_pi_blocked(tsk))
  16808. + if (!tsk->state)
  16809. + return;
  16810. + /*
  16811. + * If a worker went to sleep, notify and ask workqueue whether
  16812. + * it wants to wake up a task to maintain concurrency.
  16813. + */
  16814. + if (tsk->flags & PF_WQ_WORKER)
  16815. + wq_worker_sleeping(tsk);
  16816. +
  16817. +
  16818. + if (tsk_is_pi_blocked(tsk))
  16819. return;
  16820. +
  16821. /*
  16822. * If we are going to sleep and we have plugged IO queued,
  16823. * make sure to submit it to avoid deadlocks.
  16824. @@ -2817,6 +3043,12 @@
  16825. blk_schedule_flush_plug(tsk);
  16826. }
  16827. +static void sched_update_worker(struct task_struct *tsk)
  16828. +{
  16829. + if (tsk->flags & PF_WQ_WORKER)
  16830. + wq_worker_running(tsk);
  16831. +}
  16832. +
  16833. asmlinkage __visible void __sched schedule(void)
  16834. {
  16835. struct task_struct *tsk = current;
  16836. @@ -2825,6 +3057,7 @@
  16837. do {
  16838. __schedule();
  16839. } while (need_resched());
  16840. + sched_update_worker(tsk);
  16841. }
  16842. EXPORT_SYMBOL(schedule);
  16843. @@ -2916,6 +3149,14 @@
  16844. if (likely(!preemptible()))
  16845. return;
  16846. +#ifdef CONFIG_PREEMPT_LAZY
  16847. + /*
  16848. + * Check for lazy preemption
  16849. + */
  16850. + if (current_thread_info()->preempt_lazy_count &&
  16851. + !test_thread_flag(TIF_NEED_RESCHED))
  16852. + return;
  16853. +#endif
  16854. do {
  16855. __preempt_count_add(PREEMPT_ACTIVE);
  16856. /*
  16857. @@ -2924,7 +3165,16 @@
  16858. * an infinite recursion.
  16859. */
  16860. prev_ctx = exception_enter();
  16861. + /*
  16862. + * The add/subtract must not be traced by the function
  16863. + * tracer. But we still want to account for the
  16864. + * preempt off latency tracer. Since the _notrace versions
  16865. + * of add/subtract skip the accounting for latency tracer
  16866. + * we must force it manually.
  16867. + */
  16868. + start_critical_timings();
  16869. __schedule();
  16870. + stop_critical_timings();
  16871. exception_exit(prev_ctx);
  16872. __preempt_count_sub(PREEMPT_ACTIVE);
  16873. @@ -4261,6 +4511,7 @@
  16874. }
  16875. EXPORT_SYMBOL(__cond_resched_lock);
  16876. +#ifndef CONFIG_PREEMPT_RT_FULL
  16877. int __sched __cond_resched_softirq(void)
  16878. {
  16879. BUG_ON(!in_softirq());
  16880. @@ -4274,6 +4525,7 @@
  16881. return 0;
  16882. }
  16883. EXPORT_SYMBOL(__cond_resched_softirq);
  16884. +#endif
  16885. /**
  16886. * yield - yield the current processor to other threads.
  16887. @@ -4628,7 +4880,9 @@
  16888. /* Set the preempt count _outside_ the spinlocks! */
  16889. init_idle_preempt_count(idle, cpu);
  16890. -
  16891. +#ifdef CONFIG_HAVE_PREEMPT_LAZY
  16892. + task_thread_info(idle)->preempt_lazy_count = 0;
  16893. +#endif
  16894. /*
  16895. * The idle tasks have their own, simple scheduling class:
  16896. */
  16897. @@ -4748,11 +5002,91 @@
  16898. void do_set_cpus_allowed(struct task_struct *p, const struct cpumask *new_mask)
  16899. {
  16900. - if (p->sched_class->set_cpus_allowed)
  16901. - p->sched_class->set_cpus_allowed(p, new_mask);
  16902. + if (!migrate_disabled_updated(p)) {
  16903. + if (p->sched_class->set_cpus_allowed)
  16904. + p->sched_class->set_cpus_allowed(p, new_mask);
  16905. + p->nr_cpus_allowed = cpumask_weight(new_mask);
  16906. + }
  16907. cpumask_copy(&p->cpus_allowed, new_mask);
  16908. - p->nr_cpus_allowed = cpumask_weight(new_mask);
  16909. +}
  16910. +
  16911. +static DEFINE_PER_CPU(struct cpumask, sched_cpumasks);
  16912. +static DEFINE_MUTEX(sched_down_mutex);
  16913. +static cpumask_t sched_down_cpumask;
  16914. +
  16915. +void tell_sched_cpu_down_begin(int cpu)
  16916. +{
  16917. + mutex_lock(&sched_down_mutex);
  16918. + cpumask_set_cpu(cpu, &sched_down_cpumask);
  16919. + mutex_unlock(&sched_down_mutex);
  16920. +}
  16921. +
  16922. +void tell_sched_cpu_down_done(int cpu)
  16923. +{
  16924. + mutex_lock(&sched_down_mutex);
  16925. + cpumask_clear_cpu(cpu, &sched_down_cpumask);
  16926. + mutex_unlock(&sched_down_mutex);
  16927. +}
  16928. +
  16929. +/**
  16930. + * migrate_me - try to move the current task off this cpu
  16931. + *
  16932. + * Used by the pin_current_cpu() code to try to get tasks
  16933. + * to move off the current CPU as it is going down.
  16934. + * It will only move the task if the task isn't pinned to
  16935. + * the CPU (with migrate_disable, affinity or NO_SETAFFINITY)
  16936. + * and the task has to be in a RUNNING state. Otherwise the
  16937. + * movement of the task will wake it up (change its state
  16938. + * to running) when the task did not expect it.
  16939. + *
  16940. + * Returns 1 if it succeeded in moving the current task
  16941. + * 0 otherwise.
  16942. + */
  16943. +int migrate_me(void)
  16944. +{
  16945. + struct task_struct *p = current;
  16946. + struct migration_arg arg;
  16947. + struct cpumask *cpumask;
  16948. + struct cpumask *mask;
  16949. + unsigned long flags;
  16950. + unsigned int dest_cpu;
  16951. + struct rq *rq;
  16952. +
  16953. + /*
  16954. + * We can not migrate tasks bounded to a CPU or tasks not
  16955. + * running. The movement of the task will wake it up.
  16956. + */
  16957. + if (p->flags & PF_NO_SETAFFINITY || p->state)
  16958. + return 0;
  16959. +
  16960. + mutex_lock(&sched_down_mutex);
  16961. + rq = task_rq_lock(p, &flags);
  16962. +
  16963. + cpumask = this_cpu_ptr(&sched_cpumasks);
  16964. + mask = &p->cpus_allowed;
  16965. +
  16966. + cpumask_andnot(cpumask, mask, &sched_down_cpumask);
  16967. +
  16968. + if (!cpumask_weight(cpumask)) {
  16969. + /* It's only on this CPU? */
  16970. + task_rq_unlock(rq, p, &flags);
  16971. + mutex_unlock(&sched_down_mutex);
  16972. + return 0;
  16973. + }
  16974. +
  16975. + dest_cpu = cpumask_any_and(cpu_active_mask, cpumask);
  16976. +
  16977. + arg.task = p;
  16978. + arg.dest_cpu = dest_cpu;
  16979. +
  16980. + task_rq_unlock(rq, p, &flags);
  16981. +
  16982. + stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
  16983. + tlb_migrate_finish(p->mm);
  16984. + mutex_unlock(&sched_down_mutex);
  16985. +
  16986. + return 1;
  16987. }
  16988. /*
  16989. @@ -4798,7 +5132,7 @@
  16990. do_set_cpus_allowed(p, new_mask);
  16991. /* Can the task run on the task's current CPU? If so, we're done */
  16992. - if (cpumask_test_cpu(task_cpu(p), new_mask))
  16993. + if (cpumask_test_cpu(task_cpu(p), new_mask) || __migrate_disabled(p))
  16994. goto out;
  16995. dest_cpu = cpumask_any_and(cpu_active_mask, new_mask);
  16996. @@ -4938,6 +5272,8 @@
  16997. #ifdef CONFIG_HOTPLUG_CPU
  16998. +static DEFINE_PER_CPU(struct mm_struct *, idle_last_mm);
  16999. +
  17000. /*
  17001. * Ensures that the idle task is using init_mm right before its cpu goes
  17002. * offline.
  17003. @@ -4952,7 +5288,11 @@
  17004. switch_mm(mm, &init_mm, current);
  17005. finish_arch_post_lock_switch();
  17006. }
  17007. - mmdrop(mm);
  17008. + /*
  17009. + * Defer the cleanup to an alive cpu. On RT we can neither
  17010. + * call mmdrop() nor mmdrop_delayed() from here.
  17011. + */
  17012. + per_cpu(idle_last_mm, smp_processor_id()) = mm;
  17013. }
  17014. /*
  17015. @@ -5295,6 +5635,10 @@
  17016. case CPU_DEAD:
  17017. calc_load_migrate(rq);
  17018. + if (per_cpu(idle_last_mm, cpu)) {
  17019. + mmdrop(per_cpu(idle_last_mm, cpu));
  17020. + per_cpu(idle_last_mm, cpu) = NULL;
  17021. + }
  17022. break;
  17023. #endif
  17024. }
  17025. @@ -7266,7 +7610,8 @@
  17026. #ifdef CONFIG_DEBUG_ATOMIC_SLEEP
  17027. static inline int preempt_count_equals(int preempt_offset)
  17028. {
  17029. - int nested = (preempt_count() & ~PREEMPT_ACTIVE) + rcu_preempt_depth();
  17030. + int nested = (preempt_count() & ~PREEMPT_ACTIVE) +
  17031. + sched_rcu_preempt_depth();
  17032. return (nested == preempt_offset);
  17033. }
  17034. diff -Nur linux-4.1.6.orig/kernel/sched/cputime.c linux-4.1.6/kernel/sched/cputime.c
  17035. --- linux-4.1.6.orig/kernel/sched/cputime.c 2015-08-17 05:52:51.000000000 +0200
  17036. +++ linux-4.1.6/kernel/sched/cputime.c 2015-09-08 23:49:08.109866942 +0200
  17037. @@ -675,37 +675,45 @@
  17038. void vtime_account_system(struct task_struct *tsk)
  17039. {
  17040. - write_seqlock(&tsk->vtime_seqlock);
  17041. + raw_spin_lock(&tsk->vtime_lock);
  17042. + write_seqcount_begin(&tsk->vtime_seq);
  17043. __vtime_account_system(tsk);
  17044. - write_sequnlock(&tsk->vtime_seqlock);
  17045. + write_seqcount_end(&tsk->vtime_seq);
  17046. + raw_spin_unlock(&tsk->vtime_lock);
  17047. }
  17048. void vtime_gen_account_irq_exit(struct task_struct *tsk)
  17049. {
  17050. - write_seqlock(&tsk->vtime_seqlock);
  17051. + raw_spin_lock(&tsk->vtime_lock);
  17052. + write_seqcount_begin(&tsk->vtime_seq);
  17053. __vtime_account_system(tsk);
  17054. if (context_tracking_in_user())
  17055. tsk->vtime_snap_whence = VTIME_USER;
  17056. - write_sequnlock(&tsk->vtime_seqlock);
  17057. + write_seqcount_end(&tsk->vtime_seq);
  17058. + raw_spin_unlock(&tsk->vtime_lock);
  17059. }
  17060. void vtime_account_user(struct task_struct *tsk)
  17061. {
  17062. cputime_t delta_cpu;
  17063. - write_seqlock(&tsk->vtime_seqlock);
  17064. + raw_spin_lock(&tsk->vtime_lock);
  17065. + write_seqcount_begin(&tsk->vtime_seq);
  17066. delta_cpu = get_vtime_delta(tsk);
  17067. tsk->vtime_snap_whence = VTIME_SYS;
  17068. account_user_time(tsk, delta_cpu, cputime_to_scaled(delta_cpu));
  17069. - write_sequnlock(&tsk->vtime_seqlock);
  17070. + write_seqcount_end(&tsk->vtime_seq);
  17071. + raw_spin_unlock(&tsk->vtime_lock);
  17072. }
  17073. void vtime_user_enter(struct task_struct *tsk)
  17074. {
  17075. - write_seqlock(&tsk->vtime_seqlock);
  17076. + raw_spin_lock(&tsk->vtime_lock);
  17077. + write_seqcount_begin(&tsk->vtime_seq);
  17078. __vtime_account_system(tsk);
  17079. tsk->vtime_snap_whence = VTIME_USER;
  17080. - write_sequnlock(&tsk->vtime_seqlock);
  17081. + write_seqcount_end(&tsk->vtime_seq);
  17082. + raw_spin_unlock(&tsk->vtime_lock);
  17083. }
  17084. void vtime_guest_enter(struct task_struct *tsk)
  17085. @@ -717,19 +725,23 @@
  17086. * synchronization against the reader (task_gtime())
  17087. * that can thus safely catch up with a tickless delta.
  17088. */
  17089. - write_seqlock(&tsk->vtime_seqlock);
  17090. + raw_spin_lock(&tsk->vtime_lock);
  17091. + write_seqcount_begin(&tsk->vtime_seq);
  17092. __vtime_account_system(tsk);
  17093. current->flags |= PF_VCPU;
  17094. - write_sequnlock(&tsk->vtime_seqlock);
  17095. + write_seqcount_end(&tsk->vtime_seq);
  17096. + raw_spin_unlock(&tsk->vtime_lock);
  17097. }
  17098. EXPORT_SYMBOL_GPL(vtime_guest_enter);
  17099. void vtime_guest_exit(struct task_struct *tsk)
  17100. {
  17101. - write_seqlock(&tsk->vtime_seqlock);
  17102. + raw_spin_lock(&tsk->vtime_lock);
  17103. + write_seqcount_begin(&tsk->vtime_seq);
  17104. __vtime_account_system(tsk);
  17105. current->flags &= ~PF_VCPU;
  17106. - write_sequnlock(&tsk->vtime_seqlock);
  17107. + write_seqcount_end(&tsk->vtime_seq);
  17108. + raw_spin_unlock(&tsk->vtime_lock);
  17109. }
  17110. EXPORT_SYMBOL_GPL(vtime_guest_exit);
  17111. @@ -742,24 +754,30 @@
  17112. void arch_vtime_task_switch(struct task_struct *prev)
  17113. {
  17114. - write_seqlock(&prev->vtime_seqlock);
  17115. + raw_spin_lock(&prev->vtime_lock);
  17116. + write_seqcount_begin(&prev->vtime_seq);
  17117. prev->vtime_snap_whence = VTIME_SLEEPING;
  17118. - write_sequnlock(&prev->vtime_seqlock);
  17119. + write_seqcount_end(&prev->vtime_seq);
  17120. + raw_spin_unlock(&prev->vtime_lock);
  17121. - write_seqlock(&current->vtime_seqlock);
  17122. + raw_spin_lock(&current->vtime_lock);
  17123. + write_seqcount_begin(&current->vtime_seq);
  17124. current->vtime_snap_whence = VTIME_SYS;
  17125. current->vtime_snap = sched_clock_cpu(smp_processor_id());
  17126. - write_sequnlock(&current->vtime_seqlock);
  17127. + write_seqcount_end(&current->vtime_seq);
  17128. + raw_spin_unlock(&current->vtime_lock);
  17129. }
  17130. void vtime_init_idle(struct task_struct *t, int cpu)
  17131. {
  17132. unsigned long flags;
  17133. - write_seqlock_irqsave(&t->vtime_seqlock, flags);
  17134. + raw_spin_lock_irqsave(&t->vtime_lock, flags);
  17135. + write_seqcount_begin(&t->vtime_seq);
  17136. t->vtime_snap_whence = VTIME_SYS;
  17137. t->vtime_snap = sched_clock_cpu(cpu);
  17138. - write_sequnlock_irqrestore(&t->vtime_seqlock, flags);
  17139. + write_seqcount_end(&t->vtime_seq);
  17140. + raw_spin_unlock_irqrestore(&t->vtime_lock, flags);
  17141. }
  17142. cputime_t task_gtime(struct task_struct *t)
  17143. @@ -768,13 +786,13 @@
  17144. cputime_t gtime;
  17145. do {
  17146. - seq = read_seqbegin(&t->vtime_seqlock);
  17147. + seq = read_seqcount_begin(&t->vtime_seq);
  17148. gtime = t->gtime;
  17149. if (t->flags & PF_VCPU)
  17150. gtime += vtime_delta(t);
  17151. - } while (read_seqretry(&t->vtime_seqlock, seq));
  17152. + } while (read_seqcount_retry(&t->vtime_seq, seq));
  17153. return gtime;
  17154. }
  17155. @@ -797,7 +815,7 @@
  17156. *udelta = 0;
  17157. *sdelta = 0;
  17158. - seq = read_seqbegin(&t->vtime_seqlock);
  17159. + seq = read_seqcount_begin(&t->vtime_seq);
  17160. if (u_dst)
  17161. *u_dst = *u_src;
  17162. @@ -821,7 +839,7 @@
  17163. if (t->vtime_snap_whence == VTIME_SYS)
  17164. *sdelta = delta;
  17165. }
  17166. - } while (read_seqretry(&t->vtime_seqlock, seq));
  17167. + } while (read_seqcount_retry(&t->vtime_seq, seq));
  17168. }
  17169. diff -Nur linux-4.1.6.orig/kernel/sched/deadline.c linux-4.1.6/kernel/sched/deadline.c
  17170. --- linux-4.1.6.orig/kernel/sched/deadline.c 2015-08-17 05:52:51.000000000 +0200
  17171. +++ linux-4.1.6/kernel/sched/deadline.c 2015-09-08 23:49:08.109866942 +0200
  17172. @@ -637,6 +637,7 @@
  17173. hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  17174. timer->function = dl_task_timer;
  17175. + timer->irqsafe = 1;
  17176. }
  17177. static
  17178. diff -Nur linux-4.1.6.orig/kernel/sched/debug.c linux-4.1.6/kernel/sched/debug.c
  17179. --- linux-4.1.6.orig/kernel/sched/debug.c 2015-08-17 05:52:51.000000000 +0200
  17180. +++ linux-4.1.6/kernel/sched/debug.c 2015-09-08 23:49:08.109866942 +0200
  17181. @@ -260,6 +260,9 @@
  17182. P(rt_throttled);
  17183. PN(rt_time);
  17184. PN(rt_runtime);
  17185. +#ifdef CONFIG_SMP
  17186. + P(rt_nr_migratory);
  17187. +#endif
  17188. #undef PN
  17189. #undef P
  17190. @@ -648,6 +651,10 @@
  17191. #endif
  17192. P(policy);
  17193. P(prio);
  17194. +#ifdef CONFIG_PREEMPT_RT_FULL
  17195. + P(migrate_disable);
  17196. +#endif
  17197. + P(nr_cpus_allowed);
  17198. #undef PN
  17199. #undef __PN
  17200. #undef P
  17201. diff -Nur linux-4.1.6.orig/kernel/sched/fair.c linux-4.1.6/kernel/sched/fair.c
  17202. --- linux-4.1.6.orig/kernel/sched/fair.c 2015-08-17 05:52:51.000000000 +0200
  17203. +++ linux-4.1.6/kernel/sched/fair.c 2015-09-08 23:49:08.113866499 +0200
  17204. @@ -3201,7 +3201,7 @@
  17205. ideal_runtime = sched_slice(cfs_rq, curr);
  17206. delta_exec = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
  17207. if (delta_exec > ideal_runtime) {
  17208. - resched_curr(rq_of(cfs_rq));
  17209. + resched_curr_lazy(rq_of(cfs_rq));
  17210. /*
  17211. * The current task ran long enough, ensure it doesn't get
  17212. * re-elected due to buddy favours.
  17213. @@ -3225,7 +3225,7 @@
  17214. return;
  17215. if (delta > ideal_runtime)
  17216. - resched_curr(rq_of(cfs_rq));
  17217. + resched_curr_lazy(rq_of(cfs_rq));
  17218. }
  17219. static void
  17220. @@ -3366,7 +3366,7 @@
  17221. * validating it and just reschedule.
  17222. */
  17223. if (queued) {
  17224. - resched_curr(rq_of(cfs_rq));
  17225. + resched_curr_lazy(rq_of(cfs_rq));
  17226. return;
  17227. }
  17228. /*
  17229. @@ -3557,7 +3557,7 @@
  17230. * hierarchy can be throttled
  17231. */
  17232. if (!assign_cfs_rq_runtime(cfs_rq) && likely(cfs_rq->curr))
  17233. - resched_curr(rq_of(cfs_rq));
  17234. + resched_curr_lazy(rq_of(cfs_rq));
  17235. }
  17236. static __always_inline
  17237. @@ -4180,7 +4180,7 @@
  17238. if (delta < 0) {
  17239. if (rq->curr == p)
  17240. - resched_curr(rq);
  17241. + resched_curr_lazy(rq);
  17242. return;
  17243. }
  17244. hrtick_start(rq, delta);
  17245. @@ -5076,7 +5076,7 @@
  17246. return;
  17247. preempt:
  17248. - resched_curr(rq);
  17249. + resched_curr_lazy(rq);
  17250. /*
  17251. * Only set the backward buddy when the current task is still
  17252. * on the rq. This can happen when a wakeup gets interleaved
  17253. @@ -7866,7 +7866,7 @@
  17254. * 'current' within the tree based on its new key value.
  17255. */
  17256. swap(curr->vruntime, se->vruntime);
  17257. - resched_curr(rq);
  17258. + resched_curr_lazy(rq);
  17259. }
  17260. se->vruntime -= cfs_rq->min_vruntime;
  17261. @@ -7891,7 +7891,7 @@
  17262. */
  17263. if (rq->curr == p) {
  17264. if (p->prio > oldprio)
  17265. - resched_curr(rq);
  17266. + resched_curr_lazy(rq);
  17267. } else
  17268. check_preempt_curr(rq, p, 0);
  17269. }
  17270. diff -Nur linux-4.1.6.orig/kernel/sched/features.h linux-4.1.6/kernel/sched/features.h
  17271. --- linux-4.1.6.orig/kernel/sched/features.h 2015-08-17 05:52:51.000000000 +0200
  17272. +++ linux-4.1.6/kernel/sched/features.h 2015-09-08 23:49:08.113866499 +0200
  17273. @@ -50,11 +50,19 @@
  17274. */
  17275. SCHED_FEAT(NONTASK_CAPACITY, true)
  17276. +#ifdef CONFIG_PREEMPT_RT_FULL
  17277. +SCHED_FEAT(TTWU_QUEUE, false)
  17278. +# ifdef CONFIG_PREEMPT_LAZY
  17279. +SCHED_FEAT(PREEMPT_LAZY, true)
  17280. +# endif
  17281. +#else
  17282. +
  17283. /*
  17284. * Queue remote wakeups on the target CPU and process them
  17285. * using the scheduler IPI. Reduces rq->lock contention/bounces.
  17286. */
  17287. SCHED_FEAT(TTWU_QUEUE, true)
  17288. +#endif
  17289. #ifdef HAVE_RT_PUSH_IPI
  17290. /*
  17291. diff -Nur linux-4.1.6.orig/kernel/sched/Makefile linux-4.1.6/kernel/sched/Makefile
  17292. --- linux-4.1.6.orig/kernel/sched/Makefile 2015-08-17 05:52:51.000000000 +0200
  17293. +++ linux-4.1.6/kernel/sched/Makefile 2015-09-08 23:49:08.105867384 +0200
  17294. @@ -13,7 +13,7 @@
  17295. obj-y += core.o proc.o clock.o cputime.o
  17296. obj-y += idle_task.o fair.o rt.o deadline.o stop_task.o
  17297. -obj-y += wait.o completion.o idle.o
  17298. +obj-y += wait.o wait-simple.o work-simple.o completion.o idle.o
  17299. obj-$(CONFIG_SMP) += cpupri.o cpudeadline.o
  17300. obj-$(CONFIG_SCHED_AUTOGROUP) += auto_group.o
  17301. obj-$(CONFIG_SCHEDSTATS) += stats.o
  17302. diff -Nur linux-4.1.6.orig/kernel/sched/rt.c linux-4.1.6/kernel/sched/rt.c
  17303. --- linux-4.1.6.orig/kernel/sched/rt.c 2015-08-17 05:52:51.000000000 +0200
  17304. +++ linux-4.1.6/kernel/sched/rt.c 2015-09-08 23:49:08.113866499 +0200
  17305. @@ -44,6 +44,7 @@
  17306. hrtimer_init(&rt_b->rt_period_timer,
  17307. CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  17308. + rt_b->rt_period_timer.irqsafe = 1;
  17309. rt_b->rt_period_timer.function = sched_rt_period_timer;
  17310. }
  17311. @@ -89,6 +90,7 @@
  17312. rt_rq->push_cpu = nr_cpu_ids;
  17313. raw_spin_lock_init(&rt_rq->push_lock);
  17314. init_irq_work(&rt_rq->push_work, push_irq_work_func);
  17315. + rt_rq->push_work.flags |= IRQ_WORK_HARD_IRQ;
  17316. #endif
  17317. #endif /* CONFIG_SMP */
  17318. /* We start is dequeued state, because no RT tasks are queued */
  17319. diff -Nur linux-4.1.6.orig/kernel/sched/sched.h linux-4.1.6/kernel/sched/sched.h
  17320. --- linux-4.1.6.orig/kernel/sched/sched.h 2015-08-17 05:52:51.000000000 +0200
  17321. +++ linux-4.1.6/kernel/sched/sched.h 2015-09-08 23:49:08.113866499 +0200
  17322. @@ -1092,6 +1092,7 @@
  17323. #define WF_SYNC 0x01 /* waker goes to sleep after wakeup */
  17324. #define WF_FORK 0x02 /* child wakeup after fork */
  17325. #define WF_MIGRATED 0x4 /* internal use, task got migrated */
  17326. +#define WF_LOCK_SLEEPER 0x08 /* wakeup spinlock "sleeper" */
  17327. /*
  17328. * To aid in avoiding the subversion of "niceness" due to uneven distribution
  17329. @@ -1289,6 +1290,15 @@
  17330. extern void resched_curr(struct rq *rq);
  17331. extern void resched_cpu(int cpu);
  17332. +#ifdef CONFIG_PREEMPT_LAZY
  17333. +extern void resched_curr_lazy(struct rq *rq);
  17334. +#else
  17335. +static inline void resched_curr_lazy(struct rq *rq)
  17336. +{
  17337. + resched_curr(rq);
  17338. +}
  17339. +#endif
  17340. +
  17341. extern struct rt_bandwidth def_rt_bandwidth;
  17342. extern void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime);
  17343. diff -Nur linux-4.1.6.orig/kernel/sched/wait-simple.c linux-4.1.6/kernel/sched/wait-simple.c
  17344. --- linux-4.1.6.orig/kernel/sched/wait-simple.c 1970-01-01 01:00:00.000000000 +0100
  17345. +++ linux-4.1.6/kernel/sched/wait-simple.c 2015-09-08 23:49:08.113866499 +0200
  17346. @@ -0,0 +1,115 @@
  17347. +/*
  17348. + * Simple waitqueues without fancy flags and callbacks
  17349. + *
  17350. + * (C) 2011 Thomas Gleixner <tglx@linutronix.de>
  17351. + *
  17352. + * Based on kernel/wait.c
  17353. + *
  17354. + * For licencing details see kernel-base/COPYING
  17355. + */
  17356. +#include <linux/init.h>
  17357. +#include <linux/export.h>
  17358. +#include <linux/sched.h>
  17359. +#include <linux/wait-simple.h>
  17360. +
  17361. +/* Adds w to head->list. Must be called with head->lock locked. */
  17362. +static inline void __swait_enqueue(struct swait_head *head, struct swaiter *w)
  17363. +{
  17364. + list_add(&w->node, &head->list);
  17365. + /* We can't let the condition leak before the setting of head */
  17366. + smp_mb();
  17367. +}
  17368. +
  17369. +/* Removes w from head->list. Must be called with head->lock locked. */
  17370. +static inline void __swait_dequeue(struct swaiter *w)
  17371. +{
  17372. + list_del_init(&w->node);
  17373. +}
  17374. +
  17375. +void __init_swait_head(struct swait_head *head, struct lock_class_key *key)
  17376. +{
  17377. + raw_spin_lock_init(&head->lock);
  17378. + lockdep_set_class(&head->lock, key);
  17379. + INIT_LIST_HEAD(&head->list);
  17380. +}
  17381. +EXPORT_SYMBOL(__init_swait_head);
  17382. +
  17383. +void swait_prepare_locked(struct swait_head *head, struct swaiter *w)
  17384. +{
  17385. + w->task = current;
  17386. + if (list_empty(&w->node))
  17387. + __swait_enqueue(head, w);
  17388. +}
  17389. +
  17390. +void swait_prepare(struct swait_head *head, struct swaiter *w, int state)
  17391. +{
  17392. + unsigned long flags;
  17393. +
  17394. + raw_spin_lock_irqsave(&head->lock, flags);
  17395. + swait_prepare_locked(head, w);
  17396. + __set_current_state(state);
  17397. + raw_spin_unlock_irqrestore(&head->lock, flags);
  17398. +}
  17399. +EXPORT_SYMBOL(swait_prepare);
  17400. +
  17401. +void swait_finish_locked(struct swait_head *head, struct swaiter *w)
  17402. +{
  17403. + __set_current_state(TASK_RUNNING);
  17404. + if (w->task)
  17405. + __swait_dequeue(w);
  17406. +}
  17407. +
  17408. +void swait_finish(struct swait_head *head, struct swaiter *w)
  17409. +{
  17410. + unsigned long flags;
  17411. +
  17412. + __set_current_state(TASK_RUNNING);
  17413. + if (w->task) {
  17414. + raw_spin_lock_irqsave(&head->lock, flags);
  17415. + __swait_dequeue(w);
  17416. + raw_spin_unlock_irqrestore(&head->lock, flags);
  17417. + }
  17418. +}
  17419. +EXPORT_SYMBOL(swait_finish);
  17420. +
  17421. +unsigned int
  17422. +__swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num)
  17423. +{
  17424. + struct swaiter *curr, *next;
  17425. + int woken = 0;
  17426. +
  17427. + list_for_each_entry_safe(curr, next, &head->list, node) {
  17428. + if (wake_up_state(curr->task, state)) {
  17429. + __swait_dequeue(curr);
  17430. + /*
  17431. + * The waiting task can free the waiter as
  17432. + * soon as curr->task = NULL is written,
  17433. + * without taking any locks. A memory barrier
  17434. + * is required here to prevent the following
  17435. + * store to curr->task from getting ahead of
  17436. + * the dequeue operation.
  17437. + */
  17438. + smp_wmb();
  17439. + curr->task = NULL;
  17440. + if (++woken == num)
  17441. + break;
  17442. + }
  17443. + }
  17444. + return woken;
  17445. +}
  17446. +
  17447. +unsigned int
  17448. +__swait_wake(struct swait_head *head, unsigned int state, unsigned int num)
  17449. +{
  17450. + unsigned long flags;
  17451. + int woken;
  17452. +
  17453. + if (!swaitqueue_active(head))
  17454. + return 0;
  17455. +
  17456. + raw_spin_lock_irqsave(&head->lock, flags);
  17457. + woken = __swait_wake_locked(head, state, num);
  17458. + raw_spin_unlock_irqrestore(&head->lock, flags);
  17459. + return woken;
  17460. +}
  17461. +EXPORT_SYMBOL(__swait_wake);
  17462. diff -Nur linux-4.1.6.orig/kernel/sched/work-simple.c linux-4.1.6/kernel/sched/work-simple.c
  17463. --- linux-4.1.6.orig/kernel/sched/work-simple.c 1970-01-01 01:00:00.000000000 +0100
  17464. +++ linux-4.1.6/kernel/sched/work-simple.c 2015-09-08 23:49:08.113866499 +0200
  17465. @@ -0,0 +1,172 @@
  17466. +/*
  17467. + * Copyright (C) 2014 BMW Car IT GmbH, Daniel Wagner daniel.wagner@bmw-carit.de
  17468. + *
  17469. + * Provides a framework for enqueuing callbacks from irq context
  17470. + * PREEMPT_RT_FULL safe. The callbacks are executed in kthread context.
  17471. + */
  17472. +
  17473. +#include <linux/wait-simple.h>
  17474. +#include <linux/work-simple.h>
  17475. +#include <linux/kthread.h>
  17476. +#include <linux/slab.h>
  17477. +#include <linux/spinlock.h>
  17478. +
  17479. +#define SWORK_EVENT_PENDING (1 << 0)
  17480. +
  17481. +static DEFINE_MUTEX(worker_mutex);
  17482. +static struct sworker *glob_worker;
  17483. +
  17484. +struct sworker {
  17485. + struct list_head events;
  17486. + struct swait_head wq;
  17487. +
  17488. + raw_spinlock_t lock;
  17489. +
  17490. + struct task_struct *task;
  17491. + int refs;
  17492. +};
  17493. +
  17494. +static bool swork_readable(struct sworker *worker)
  17495. +{
  17496. + bool r;
  17497. +
  17498. + if (kthread_should_stop())
  17499. + return true;
  17500. +
  17501. + raw_spin_lock_irq(&worker->lock);
  17502. + r = !list_empty(&worker->events);
  17503. + raw_spin_unlock_irq(&worker->lock);
  17504. +
  17505. + return r;
  17506. +}
  17507. +
  17508. +static int swork_kthread(void *arg)
  17509. +{
  17510. + struct sworker *worker = arg;
  17511. +
  17512. + for (;;) {
  17513. + swait_event_interruptible(worker->wq,
  17514. + swork_readable(worker));
  17515. + if (kthread_should_stop())
  17516. + break;
  17517. +
  17518. + raw_spin_lock_irq(&worker->lock);
  17519. + while (!list_empty(&worker->events)) {
  17520. + struct swork_event *sev;
  17521. +
  17522. + sev = list_first_entry(&worker->events,
  17523. + struct swork_event, item);
  17524. + list_del(&sev->item);
  17525. + raw_spin_unlock_irq(&worker->lock);
  17526. +
  17527. + WARN_ON_ONCE(!test_and_clear_bit(SWORK_EVENT_PENDING,
  17528. + &sev->flags));
  17529. + sev->func(sev);
  17530. + raw_spin_lock_irq(&worker->lock);
  17531. + }
  17532. + raw_spin_unlock_irq(&worker->lock);
  17533. + }
  17534. + return 0;
  17535. +}
  17536. +
  17537. +static struct sworker *swork_create(void)
  17538. +{
  17539. + struct sworker *worker;
  17540. +
  17541. + worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  17542. + if (!worker)
  17543. + return ERR_PTR(-ENOMEM);
  17544. +
  17545. + INIT_LIST_HEAD(&worker->events);
  17546. + raw_spin_lock_init(&worker->lock);
  17547. + init_swait_head(&worker->wq);
  17548. +
  17549. + worker->task = kthread_run(swork_kthread, worker, "kswork");
  17550. + if (IS_ERR(worker->task)) {
  17551. + kfree(worker);
  17552. + return ERR_PTR(-ENOMEM);
  17553. + }
  17554. +
  17555. + return worker;
  17556. +}
  17557. +
  17558. +static void swork_destroy(struct sworker *worker)
  17559. +{
  17560. + kthread_stop(worker->task);
  17561. +
  17562. + WARN_ON(!list_empty(&worker->events));
  17563. + kfree(worker);
  17564. +}
  17565. +
  17566. +/**
  17567. + * swork_queue - queue swork
  17568. + *
  17569. + * Returns %false if @work was already on a queue, %true otherwise.
  17570. + *
  17571. + * The work is queued and processed on a random CPU
  17572. + */
  17573. +bool swork_queue(struct swork_event *sev)
  17574. +{
  17575. + unsigned long flags;
  17576. +
  17577. + if (test_and_set_bit(SWORK_EVENT_PENDING, &sev->flags))
  17578. + return false;
  17579. +
  17580. + raw_spin_lock_irqsave(&glob_worker->lock, flags);
  17581. + list_add_tail(&sev->item, &glob_worker->events);
  17582. + raw_spin_unlock_irqrestore(&glob_worker->lock, flags);
  17583. +
  17584. + swait_wake(&glob_worker->wq);
  17585. + return true;
  17586. +}
  17587. +EXPORT_SYMBOL_GPL(swork_queue);
  17588. +
  17589. +/**
  17590. + * swork_get - get an instance of the sworker
  17591. + *
  17592. + * Returns an negative error code if the initialization if the worker did not
  17593. + * work, %0 otherwise.
  17594. + *
  17595. + */
  17596. +int swork_get(void)
  17597. +{
  17598. + struct sworker *worker;
  17599. +
  17600. + mutex_lock(&worker_mutex);
  17601. + if (!glob_worker) {
  17602. + worker = swork_create();
  17603. + if (IS_ERR(worker)) {
  17604. + mutex_unlock(&worker_mutex);
  17605. + return -ENOMEM;
  17606. + }
  17607. +
  17608. + glob_worker = worker;
  17609. + }
  17610. +
  17611. + glob_worker->refs++;
  17612. + mutex_unlock(&worker_mutex);
  17613. +
  17614. + return 0;
  17615. +}
  17616. +EXPORT_SYMBOL_GPL(swork_get);
  17617. +
  17618. +/**
  17619. + * swork_put - puts an instance of the sworker
  17620. + *
  17621. + * Will destroy the sworker thread. This function must not be called until all
  17622. + * queued events have been completed.
  17623. + */
  17624. +void swork_put(void)
  17625. +{
  17626. + mutex_lock(&worker_mutex);
  17627. +
  17628. + glob_worker->refs--;
  17629. + if (glob_worker->refs > 0)
  17630. + goto out;
  17631. +
  17632. + swork_destroy(glob_worker);
  17633. + glob_worker = NULL;
  17634. +out:
  17635. + mutex_unlock(&worker_mutex);
  17636. +}
  17637. +EXPORT_SYMBOL_GPL(swork_put);
  17638. diff -Nur linux-4.1.6.orig/kernel/signal.c linux-4.1.6/kernel/signal.c
  17639. --- linux-4.1.6.orig/kernel/signal.c 2015-08-17 05:52:51.000000000 +0200
  17640. +++ linux-4.1.6/kernel/signal.c 2015-09-08 23:49:08.113866499 +0200
  17641. @@ -14,6 +14,7 @@
  17642. #include <linux/export.h>
  17643. #include <linux/init.h>
  17644. #include <linux/sched.h>
  17645. +#include <linux/sched/rt.h>
  17646. #include <linux/fs.h>
  17647. #include <linux/tty.h>
  17648. #include <linux/binfmts.h>
  17649. @@ -352,13 +353,45 @@
  17650. return false;
  17651. }
  17652. +#ifdef __HAVE_ARCH_CMPXCHG
  17653. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  17654. +{
  17655. + struct sigqueue *q = t->sigqueue_cache;
  17656. +
  17657. + if (cmpxchg(&t->sigqueue_cache, q, NULL) != q)
  17658. + return NULL;
  17659. + return q;
  17660. +}
  17661. +
  17662. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  17663. +{
  17664. + if (cmpxchg(&t->sigqueue_cache, NULL, q) == NULL)
  17665. + return 0;
  17666. + return 1;
  17667. +}
  17668. +
  17669. +#else
  17670. +
  17671. +static inline struct sigqueue *get_task_cache(struct task_struct *t)
  17672. +{
  17673. + return NULL;
  17674. +}
  17675. +
  17676. +static inline int put_task_cache(struct task_struct *t, struct sigqueue *q)
  17677. +{
  17678. + return 1;
  17679. +}
  17680. +
  17681. +#endif
  17682. +
  17683. /*
  17684. * allocate a new signal queue record
  17685. * - this may be called without locks if and only if t == current, otherwise an
  17686. * appropriate lock must be held to stop the target task from exiting
  17687. */
  17688. static struct sigqueue *
  17689. -__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimit)
  17690. +__sigqueue_do_alloc(int sig, struct task_struct *t, gfp_t flags,
  17691. + int override_rlimit, int fromslab)
  17692. {
  17693. struct sigqueue *q = NULL;
  17694. struct user_struct *user;
  17695. @@ -375,7 +408,10 @@
  17696. if (override_rlimit ||
  17697. atomic_read(&user->sigpending) <=
  17698. task_rlimit(t, RLIMIT_SIGPENDING)) {
  17699. - q = kmem_cache_alloc(sigqueue_cachep, flags);
  17700. + if (!fromslab)
  17701. + q = get_task_cache(t);
  17702. + if (!q)
  17703. + q = kmem_cache_alloc(sigqueue_cachep, flags);
  17704. } else {
  17705. print_dropped_signal(sig);
  17706. }
  17707. @@ -392,6 +428,13 @@
  17708. return q;
  17709. }
  17710. +static struct sigqueue *
  17711. +__sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags,
  17712. + int override_rlimit)
  17713. +{
  17714. + return __sigqueue_do_alloc(sig, t, flags, override_rlimit, 0);
  17715. +}
  17716. +
  17717. static void __sigqueue_free(struct sigqueue *q)
  17718. {
  17719. if (q->flags & SIGQUEUE_PREALLOC)
  17720. @@ -401,6 +444,21 @@
  17721. kmem_cache_free(sigqueue_cachep, q);
  17722. }
  17723. +static void sigqueue_free_current(struct sigqueue *q)
  17724. +{
  17725. + struct user_struct *up;
  17726. +
  17727. + if (q->flags & SIGQUEUE_PREALLOC)
  17728. + return;
  17729. +
  17730. + up = q->user;
  17731. + if (rt_prio(current->normal_prio) && !put_task_cache(current, q)) {
  17732. + atomic_dec(&up->sigpending);
  17733. + free_uid(up);
  17734. + } else
  17735. + __sigqueue_free(q);
  17736. +}
  17737. +
  17738. void flush_sigqueue(struct sigpending *queue)
  17739. {
  17740. struct sigqueue *q;
  17741. @@ -414,6 +472,21 @@
  17742. }
  17743. /*
  17744. + * Called from __exit_signal. Flush tsk->pending and
  17745. + * tsk->sigqueue_cache
  17746. + */
  17747. +void flush_task_sigqueue(struct task_struct *tsk)
  17748. +{
  17749. + struct sigqueue *q;
  17750. +
  17751. + flush_sigqueue(&tsk->pending);
  17752. +
  17753. + q = get_task_cache(tsk);
  17754. + if (q)
  17755. + kmem_cache_free(sigqueue_cachep, q);
  17756. +}
  17757. +
  17758. +/*
  17759. * Flush all pending signals for a task.
  17760. */
  17761. void __flush_signals(struct task_struct *t)
  17762. @@ -565,7 +638,7 @@
  17763. still_pending:
  17764. list_del_init(&first->list);
  17765. copy_siginfo(info, &first->info);
  17766. - __sigqueue_free(first);
  17767. + sigqueue_free_current(first);
  17768. } else {
  17769. /*
  17770. * Ok, it wasn't in the queue. This must be
  17771. @@ -611,6 +684,8 @@
  17772. {
  17773. int signr;
  17774. + WARN_ON_ONCE(tsk != current);
  17775. +
  17776. /* We only dequeue private signals from ourselves, we don't let
  17777. * signalfd steal them
  17778. */
  17779. @@ -1207,8 +1282,8 @@
  17780. * We don't want to have recursive SIGSEGV's etc, for example,
  17781. * that is why we also clear SIGNAL_UNKILLABLE.
  17782. */
  17783. -int
  17784. -force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  17785. +static int
  17786. +do_force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  17787. {
  17788. unsigned long int flags;
  17789. int ret, blocked, ignored;
  17790. @@ -1233,6 +1308,39 @@
  17791. return ret;
  17792. }
  17793. +int force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
  17794. +{
  17795. +/*
  17796. + * On some archs, PREEMPT_RT has to delay sending a signal from a trap
  17797. + * since it can not enable preemption, and the signal code's spin_locks
  17798. + * turn into mutexes. Instead, it must set TIF_NOTIFY_RESUME which will
  17799. + * send the signal on exit of the trap.
  17800. + */
  17801. +#ifdef ARCH_RT_DELAYS_SIGNAL_SEND
  17802. + if (in_atomic()) {
  17803. + if (WARN_ON_ONCE(t != current))
  17804. + return 0;
  17805. + if (WARN_ON_ONCE(t->forced_info.si_signo))
  17806. + return 0;
  17807. +
  17808. + if (is_si_special(info)) {
  17809. + WARN_ON_ONCE(info != SEND_SIG_PRIV);
  17810. + t->forced_info.si_signo = sig;
  17811. + t->forced_info.si_errno = 0;
  17812. + t->forced_info.si_code = SI_KERNEL;
  17813. + t->forced_info.si_pid = 0;
  17814. + t->forced_info.si_uid = 0;
  17815. + } else {
  17816. + t->forced_info = *info;
  17817. + }
  17818. +
  17819. + set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
  17820. + return 0;
  17821. + }
  17822. +#endif
  17823. + return do_force_sig_info(sig, info, t);
  17824. +}
  17825. +
  17826. /*
  17827. * Nuke all other threads in the group.
  17828. */
  17829. @@ -1267,12 +1375,12 @@
  17830. * Disable interrupts early to avoid deadlocks.
  17831. * See rcu_read_unlock() comment header for details.
  17832. */
  17833. - local_irq_save(*flags);
  17834. + local_irq_save_nort(*flags);
  17835. rcu_read_lock();
  17836. sighand = rcu_dereference(tsk->sighand);
  17837. if (unlikely(sighand == NULL)) {
  17838. rcu_read_unlock();
  17839. - local_irq_restore(*flags);
  17840. + local_irq_restore_nort(*flags);
  17841. break;
  17842. }
  17843. /*
  17844. @@ -1293,7 +1401,7 @@
  17845. }
  17846. spin_unlock(&sighand->siglock);
  17847. rcu_read_unlock();
  17848. - local_irq_restore(*flags);
  17849. + local_irq_restore_nort(*flags);
  17850. }
  17851. return sighand;
  17852. @@ -1536,7 +1644,8 @@
  17853. */
  17854. struct sigqueue *sigqueue_alloc(void)
  17855. {
  17856. - struct sigqueue *q = __sigqueue_alloc(-1, current, GFP_KERNEL, 0);
  17857. + /* Preallocated sigqueue objects always from the slabcache ! */
  17858. + struct sigqueue *q = __sigqueue_do_alloc(-1, current, GFP_KERNEL, 0, 1);
  17859. if (q)
  17860. q->flags |= SIGQUEUE_PREALLOC;
  17861. @@ -1897,15 +2006,7 @@
  17862. if (gstop_done && ptrace_reparented(current))
  17863. do_notify_parent_cldstop(current, false, why);
  17864. - /*
  17865. - * Don't want to allow preemption here, because
  17866. - * sys_ptrace() needs this task to be inactive.
  17867. - *
  17868. - * XXX: implement read_unlock_no_resched().
  17869. - */
  17870. - preempt_disable();
  17871. read_unlock(&tasklist_lock);
  17872. - preempt_enable_no_resched();
  17873. freezable_schedule();
  17874. } else {
  17875. /*
  17876. diff -Nur linux-4.1.6.orig/kernel/softirq.c linux-4.1.6/kernel/softirq.c
  17877. --- linux-4.1.6.orig/kernel/softirq.c 2015-08-17 05:52:51.000000000 +0200
  17878. +++ linux-4.1.6/kernel/softirq.c 2015-09-08 23:49:08.117866054 +0200
  17879. @@ -21,10 +21,12 @@
  17880. #include <linux/freezer.h>
  17881. #include <linux/kthread.h>
  17882. #include <linux/rcupdate.h>
  17883. +#include <linux/delay.h>
  17884. #include <linux/ftrace.h>
  17885. #include <linux/smp.h>
  17886. #include <linux/smpboot.h>
  17887. #include <linux/tick.h>
  17888. +#include <linux/locallock.h>
  17889. #include <linux/irq.h>
  17890. #define CREATE_TRACE_POINTS
  17891. @@ -62,6 +64,98 @@
  17892. "TASKLET", "SCHED", "HRTIMER", "RCU"
  17893. };
  17894. +#ifdef CONFIG_NO_HZ_COMMON
  17895. +# ifdef CONFIG_PREEMPT_RT_FULL
  17896. +
  17897. +struct softirq_runner {
  17898. + struct task_struct *runner[NR_SOFTIRQS];
  17899. +};
  17900. +
  17901. +static DEFINE_PER_CPU(struct softirq_runner, softirq_runners);
  17902. +
  17903. +static inline void softirq_set_runner(unsigned int sirq)
  17904. +{
  17905. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  17906. +
  17907. + sr->runner[sirq] = current;
  17908. +}
  17909. +
  17910. +static inline void softirq_clr_runner(unsigned int sirq)
  17911. +{
  17912. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  17913. +
  17914. + sr->runner[sirq] = NULL;
  17915. +}
  17916. +
  17917. +/*
  17918. + * On preempt-rt a softirq running context might be blocked on a
  17919. + * lock. There might be no other runnable task on this CPU because the
  17920. + * lock owner runs on some other CPU. So we have to go into idle with
  17921. + * the pending bit set. Therefor we need to check this otherwise we
  17922. + * warn about false positives which confuses users and defeats the
  17923. + * whole purpose of this test.
  17924. + *
  17925. + * This code is called with interrupts disabled.
  17926. + */
  17927. +void softirq_check_pending_idle(void)
  17928. +{
  17929. + static int rate_limit;
  17930. + struct softirq_runner *sr = this_cpu_ptr(&softirq_runners);
  17931. + u32 warnpending;
  17932. + int i;
  17933. +
  17934. + if (rate_limit >= 10)
  17935. + return;
  17936. +
  17937. + warnpending = local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK;
  17938. + for (i = 0; i < NR_SOFTIRQS; i++) {
  17939. + struct task_struct *tsk = sr->runner[i];
  17940. +
  17941. + /*
  17942. + * The wakeup code in rtmutex.c wakes up the task
  17943. + * _before_ it sets pi_blocked_on to NULL under
  17944. + * tsk->pi_lock. So we need to check for both: state
  17945. + * and pi_blocked_on.
  17946. + */
  17947. + if (tsk) {
  17948. + raw_spin_lock(&tsk->pi_lock);
  17949. + if (tsk->pi_blocked_on || tsk->state == TASK_RUNNING) {
  17950. + /* Clear all bits pending in that task */
  17951. + warnpending &= ~(tsk->softirqs_raised);
  17952. + warnpending &= ~(1 << i);
  17953. + }
  17954. + raw_spin_unlock(&tsk->pi_lock);
  17955. + }
  17956. + }
  17957. +
  17958. + if (warnpending) {
  17959. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  17960. + warnpending);
  17961. + rate_limit++;
  17962. + }
  17963. +}
  17964. +# else
  17965. +/*
  17966. + * On !PREEMPT_RT we just printk rate limited:
  17967. + */
  17968. +void softirq_check_pending_idle(void)
  17969. +{
  17970. + static int rate_limit;
  17971. +
  17972. + if (rate_limit < 10 &&
  17973. + (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  17974. + printk(KERN_ERR "NOHZ: local_softirq_pending %02x\n",
  17975. + local_softirq_pending());
  17976. + rate_limit++;
  17977. + }
  17978. +}
  17979. +# endif
  17980. +
  17981. +#else /* !CONFIG_NO_HZ_COMMON */
  17982. +static inline void softirq_set_runner(unsigned int sirq) { }
  17983. +static inline void softirq_clr_runner(unsigned int sirq) { }
  17984. +#endif
  17985. +
  17986. /*
  17987. * we cannot loop indefinitely here to avoid userspace starvation,
  17988. * but we also don't want to introduce a worst case 1/HZ latency
  17989. @@ -77,6 +171,68 @@
  17990. wake_up_process(tsk);
  17991. }
  17992. +static void handle_softirq(unsigned int vec_nr)
  17993. +{
  17994. + struct softirq_action *h = softirq_vec + vec_nr;
  17995. + int prev_count;
  17996. +
  17997. + prev_count = preempt_count();
  17998. +
  17999. + kstat_incr_softirqs_this_cpu(vec_nr);
  18000. +
  18001. + trace_softirq_entry(vec_nr);
  18002. + h->action(h);
  18003. + trace_softirq_exit(vec_nr);
  18004. + if (unlikely(prev_count != preempt_count())) {
  18005. + pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  18006. + vec_nr, softirq_to_name[vec_nr], h->action,
  18007. + prev_count, preempt_count());
  18008. + preempt_count_set(prev_count);
  18009. + }
  18010. +}
  18011. +
  18012. +#ifndef CONFIG_PREEMPT_RT_FULL
  18013. +static inline int ksoftirqd_softirq_pending(void)
  18014. +{
  18015. + return local_softirq_pending();
  18016. +}
  18017. +
  18018. +static void handle_pending_softirqs(u32 pending)
  18019. +{
  18020. + struct softirq_action *h = softirq_vec;
  18021. + int softirq_bit;
  18022. +
  18023. + local_irq_enable();
  18024. +
  18025. + h = softirq_vec;
  18026. +
  18027. + while ((softirq_bit = ffs(pending))) {
  18028. + unsigned int vec_nr;
  18029. +
  18030. + h += softirq_bit - 1;
  18031. + vec_nr = h - softirq_vec;
  18032. + handle_softirq(vec_nr);
  18033. +
  18034. + h++;
  18035. + pending >>= softirq_bit;
  18036. + }
  18037. +
  18038. + rcu_bh_qs();
  18039. + local_irq_disable();
  18040. +}
  18041. +
  18042. +static void run_ksoftirqd(unsigned int cpu)
  18043. +{
  18044. + local_irq_disable();
  18045. + if (ksoftirqd_softirq_pending()) {
  18046. + __do_softirq();
  18047. + local_irq_enable();
  18048. + cond_resched_rcu_qs();
  18049. + return;
  18050. + }
  18051. + local_irq_enable();
  18052. +}
  18053. +
  18054. /*
  18055. * preempt_count and SOFTIRQ_OFFSET usage:
  18056. * - preempt_count is changed by SOFTIRQ_OFFSET on entering or leaving
  18057. @@ -232,10 +388,8 @@
  18058. unsigned long end = jiffies + MAX_SOFTIRQ_TIME;
  18059. unsigned long old_flags = current->flags;
  18060. int max_restart = MAX_SOFTIRQ_RESTART;
  18061. - struct softirq_action *h;
  18062. bool in_hardirq;
  18063. __u32 pending;
  18064. - int softirq_bit;
  18065. /*
  18066. * Mask out PF_MEMALLOC s current task context is borrowed for the
  18067. @@ -254,36 +408,7 @@
  18068. /* Reset the pending bitmask before enabling irqs */
  18069. set_softirq_pending(0);
  18070. - local_irq_enable();
  18071. -
  18072. - h = softirq_vec;
  18073. -
  18074. - while ((softirq_bit = ffs(pending))) {
  18075. - unsigned int vec_nr;
  18076. - int prev_count;
  18077. -
  18078. - h += softirq_bit - 1;
  18079. -
  18080. - vec_nr = h - softirq_vec;
  18081. - prev_count = preempt_count();
  18082. -
  18083. - kstat_incr_softirqs_this_cpu(vec_nr);
  18084. -
  18085. - trace_softirq_entry(vec_nr);
  18086. - h->action(h);
  18087. - trace_softirq_exit(vec_nr);
  18088. - if (unlikely(prev_count != preempt_count())) {
  18089. - pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
  18090. - vec_nr, softirq_to_name[vec_nr], h->action,
  18091. - prev_count, preempt_count());
  18092. - preempt_count_set(prev_count);
  18093. - }
  18094. - h++;
  18095. - pending >>= softirq_bit;
  18096. - }
  18097. -
  18098. - rcu_bh_qs();
  18099. - local_irq_disable();
  18100. + handle_pending_softirqs(pending);
  18101. pending = local_softirq_pending();
  18102. if (pending) {
  18103. @@ -320,6 +445,285 @@
  18104. }
  18105. /*
  18106. + * This function must run with irqs disabled!
  18107. + */
  18108. +void raise_softirq_irqoff(unsigned int nr)
  18109. +{
  18110. + __raise_softirq_irqoff(nr);
  18111. +
  18112. + /*
  18113. + * If we're in an interrupt or softirq, we're done
  18114. + * (this also catches softirq-disabled code). We will
  18115. + * actually run the softirq once we return from
  18116. + * the irq or softirq.
  18117. + *
  18118. + * Otherwise we wake up ksoftirqd to make sure we
  18119. + * schedule the softirq soon.
  18120. + */
  18121. + if (!in_interrupt())
  18122. + wakeup_softirqd();
  18123. +}
  18124. +
  18125. +void __raise_softirq_irqoff(unsigned int nr)
  18126. +{
  18127. + trace_softirq_raise(nr);
  18128. + or_softirq_pending(1UL << nr);
  18129. +}
  18130. +
  18131. +static inline void local_bh_disable_nort(void) { local_bh_disable(); }
  18132. +static inline void _local_bh_enable_nort(void) { _local_bh_enable(); }
  18133. +static void ksoftirqd_set_sched_params(unsigned int cpu) { }
  18134. +static void ksoftirqd_clr_sched_params(unsigned int cpu, bool online) { }
  18135. +
  18136. +#else /* !PREEMPT_RT_FULL */
  18137. +
  18138. +/*
  18139. + * On RT we serialize softirq execution with a cpu local lock per softirq
  18140. + */
  18141. +static DEFINE_PER_CPU(struct local_irq_lock [NR_SOFTIRQS], local_softirq_locks);
  18142. +
  18143. +void __init softirq_early_init(void)
  18144. +{
  18145. + int i;
  18146. +
  18147. + for (i = 0; i < NR_SOFTIRQS; i++)
  18148. + local_irq_lock_init(local_softirq_locks[i]);
  18149. +}
  18150. +
  18151. +static void lock_softirq(int which)
  18152. +{
  18153. + local_lock(local_softirq_locks[which]);
  18154. +}
  18155. +
  18156. +static void unlock_softirq(int which)
  18157. +{
  18158. + local_unlock(local_softirq_locks[which]);
  18159. +}
  18160. +
  18161. +static void do_single_softirq(int which)
  18162. +{
  18163. + unsigned long old_flags = current->flags;
  18164. +
  18165. + current->flags &= ~PF_MEMALLOC;
  18166. + vtime_account_irq_enter(current);
  18167. + current->flags |= PF_IN_SOFTIRQ;
  18168. + lockdep_softirq_enter();
  18169. + local_irq_enable();
  18170. + handle_softirq(which);
  18171. + local_irq_disable();
  18172. + lockdep_softirq_exit();
  18173. + current->flags &= ~PF_IN_SOFTIRQ;
  18174. + vtime_account_irq_enter(current);
  18175. + tsk_restore_flags(current, old_flags, PF_MEMALLOC);
  18176. +}
  18177. +
  18178. +/*
  18179. + * Called with interrupts disabled. Process softirqs which were raised
  18180. + * in current context (or on behalf of ksoftirqd).
  18181. + */
  18182. +static void do_current_softirqs(void)
  18183. +{
  18184. + while (current->softirqs_raised) {
  18185. + int i = __ffs(current->softirqs_raised);
  18186. + unsigned int pending, mask = (1U << i);
  18187. +
  18188. + current->softirqs_raised &= ~mask;
  18189. + local_irq_enable();
  18190. +
  18191. + /*
  18192. + * If the lock is contended, we boost the owner to
  18193. + * process the softirq or leave the critical section
  18194. + * now.
  18195. + */
  18196. + lock_softirq(i);
  18197. + local_irq_disable();
  18198. + softirq_set_runner(i);
  18199. + /*
  18200. + * Check with the local_softirq_pending() bits,
  18201. + * whether we need to process this still or if someone
  18202. + * else took care of it.
  18203. + */
  18204. + pending = local_softirq_pending();
  18205. + if (pending & mask) {
  18206. + set_softirq_pending(pending & ~mask);
  18207. + do_single_softirq(i);
  18208. + }
  18209. + softirq_clr_runner(i);
  18210. + unlock_softirq(i);
  18211. + WARN_ON(current->softirq_nestcnt != 1);
  18212. + }
  18213. +}
  18214. +
  18215. +static void __local_bh_disable(void)
  18216. +{
  18217. + if (++current->softirq_nestcnt == 1)
  18218. + migrate_disable();
  18219. +}
  18220. +
  18221. +void local_bh_disable(void)
  18222. +{
  18223. + __local_bh_disable();
  18224. +}
  18225. +EXPORT_SYMBOL(local_bh_disable);
  18226. +
  18227. +void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
  18228. +{
  18229. + __local_bh_disable();
  18230. + if (cnt & PREEMPT_CHECK_OFFSET)
  18231. + preempt_disable();
  18232. +}
  18233. +
  18234. +static void __local_bh_enable(void)
  18235. +{
  18236. + if (WARN_ON(current->softirq_nestcnt == 0))
  18237. + return;
  18238. +
  18239. + local_irq_disable();
  18240. + if (current->softirq_nestcnt == 1 && current->softirqs_raised)
  18241. + do_current_softirqs();
  18242. + local_irq_enable();
  18243. +
  18244. + if (--current->softirq_nestcnt == 0)
  18245. + migrate_enable();
  18246. +}
  18247. +
  18248. +void local_bh_enable(void)
  18249. +{
  18250. + __local_bh_enable();
  18251. +}
  18252. +EXPORT_SYMBOL(local_bh_enable);
  18253. +
  18254. +extern void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
  18255. +{
  18256. + __local_bh_enable();
  18257. + if (cnt & PREEMPT_CHECK_OFFSET)
  18258. + preempt_enable();
  18259. +}
  18260. +
  18261. +void local_bh_enable_ip(unsigned long ip)
  18262. +{
  18263. + local_bh_enable();
  18264. +}
  18265. +EXPORT_SYMBOL(local_bh_enable_ip);
  18266. +
  18267. +void _local_bh_enable(void)
  18268. +{
  18269. + if (WARN_ON(current->softirq_nestcnt == 0))
  18270. + return;
  18271. + if (--current->softirq_nestcnt == 0)
  18272. + migrate_enable();
  18273. +}
  18274. +EXPORT_SYMBOL(_local_bh_enable);
  18275. +
  18276. +int in_serving_softirq(void)
  18277. +{
  18278. + return current->flags & PF_IN_SOFTIRQ;
  18279. +}
  18280. +EXPORT_SYMBOL(in_serving_softirq);
  18281. +
  18282. +/* Called with preemption disabled */
  18283. +static void run_ksoftirqd(unsigned int cpu)
  18284. +{
  18285. + local_irq_disable();
  18286. + current->softirq_nestcnt++;
  18287. +
  18288. + do_current_softirqs();
  18289. + current->softirq_nestcnt--;
  18290. + rcu_note_context_switch();
  18291. + local_irq_enable();
  18292. +}
  18293. +
  18294. +/*
  18295. + * Called from netif_rx_ni(). Preemption enabled, but migration
  18296. + * disabled. So the cpu can't go away under us.
  18297. + */
  18298. +void thread_do_softirq(void)
  18299. +{
  18300. + if (!in_serving_softirq() && current->softirqs_raised) {
  18301. + current->softirq_nestcnt++;
  18302. + do_current_softirqs();
  18303. + current->softirq_nestcnt--;
  18304. + }
  18305. +}
  18306. +
  18307. +static void do_raise_softirq_irqoff(unsigned int nr)
  18308. +{
  18309. + trace_softirq_raise(nr);
  18310. + or_softirq_pending(1UL << nr);
  18311. +
  18312. + /*
  18313. + * If we are not in a hard interrupt and inside a bh disabled
  18314. + * region, we simply raise the flag on current. local_bh_enable()
  18315. + * will make sure that the softirq is executed. Otherwise we
  18316. + * delegate it to ksoftirqd.
  18317. + */
  18318. + if (!in_irq() && current->softirq_nestcnt)
  18319. + current->softirqs_raised |= (1U << nr);
  18320. + else if (__this_cpu_read(ksoftirqd))
  18321. + __this_cpu_read(ksoftirqd)->softirqs_raised |= (1U << nr);
  18322. +}
  18323. +
  18324. +void __raise_softirq_irqoff(unsigned int nr)
  18325. +{
  18326. + do_raise_softirq_irqoff(nr);
  18327. + if (!in_irq() && !current->softirq_nestcnt)
  18328. + wakeup_softirqd();
  18329. +}
  18330. +
  18331. +/*
  18332. + * This function must run with irqs disabled!
  18333. + */
  18334. +void raise_softirq_irqoff(unsigned int nr)
  18335. +{
  18336. + do_raise_softirq_irqoff(nr);
  18337. +
  18338. + /*
  18339. + * If we're in an hard interrupt we let irq return code deal
  18340. + * with the wakeup of ksoftirqd.
  18341. + */
  18342. + if (in_irq())
  18343. + return;
  18344. + /*
  18345. + * If we are in thread context but outside of a bh disabled
  18346. + * region, we need to wake ksoftirqd as well.
  18347. + *
  18348. + * CHECKME: Some of the places which do that could be wrapped
  18349. + * into local_bh_disable/enable pairs. Though it's unclear
  18350. + * whether this is worth the effort. To find those places just
  18351. + * raise a WARN() if the condition is met.
  18352. + */
  18353. + if (!current->softirq_nestcnt)
  18354. + wakeup_softirqd();
  18355. +}
  18356. +
  18357. +static inline int ksoftirqd_softirq_pending(void)
  18358. +{
  18359. + return current->softirqs_raised;
  18360. +}
  18361. +
  18362. +static inline void local_bh_disable_nort(void) { }
  18363. +static inline void _local_bh_enable_nort(void) { }
  18364. +
  18365. +static inline void ksoftirqd_set_sched_params(unsigned int cpu)
  18366. +{
  18367. + struct sched_param param = { .sched_priority = 1 };
  18368. +
  18369. + sched_setscheduler(current, SCHED_FIFO, &param);
  18370. + /* Take over all pending softirqs when starting */
  18371. + local_irq_disable();
  18372. + current->softirqs_raised = local_softirq_pending();
  18373. + local_irq_enable();
  18374. +}
  18375. +
  18376. +static inline void ksoftirqd_clr_sched_params(unsigned int cpu, bool online)
  18377. +{
  18378. + struct sched_param param = { .sched_priority = 0 };
  18379. +
  18380. + sched_setscheduler(current, SCHED_NORMAL, &param);
  18381. +}
  18382. +
  18383. +#endif /* PREEMPT_RT_FULL */
  18384. +/*
  18385. * Enter an interrupt context.
  18386. */
  18387. void irq_enter(void)
  18388. @@ -330,9 +734,9 @@
  18389. * Prevent raise_softirq from needlessly waking up ksoftirqd
  18390. * here, as softirq will be serviced on return from interrupt.
  18391. */
  18392. - local_bh_disable();
  18393. + local_bh_disable_nort();
  18394. tick_irq_enter();
  18395. - _local_bh_enable();
  18396. + _local_bh_enable_nort();
  18397. }
  18398. __irq_enter();
  18399. @@ -340,6 +744,7 @@
  18400. static inline void invoke_softirq(void)
  18401. {
  18402. +#ifndef CONFIG_PREEMPT_RT_FULL
  18403. if (!force_irqthreads) {
  18404. #ifdef CONFIG_HAVE_IRQ_EXIT_ON_IRQ_STACK
  18405. /*
  18406. @@ -359,6 +764,15 @@
  18407. } else {
  18408. wakeup_softirqd();
  18409. }
  18410. +#else /* PREEMPT_RT_FULL */
  18411. + unsigned long flags;
  18412. +
  18413. + local_irq_save(flags);
  18414. + if (__this_cpu_read(ksoftirqd) &&
  18415. + __this_cpu_read(ksoftirqd)->softirqs_raised)
  18416. + wakeup_softirqd();
  18417. + local_irq_restore(flags);
  18418. +#endif
  18419. }
  18420. static inline void tick_irq_exit(void)
  18421. @@ -395,26 +809,6 @@
  18422. trace_hardirq_exit(); /* must be last! */
  18423. }
  18424. -/*
  18425. - * This function must run with irqs disabled!
  18426. - */
  18427. -inline void raise_softirq_irqoff(unsigned int nr)
  18428. -{
  18429. - __raise_softirq_irqoff(nr);
  18430. -
  18431. - /*
  18432. - * If we're in an interrupt or softirq, we're done
  18433. - * (this also catches softirq-disabled code). We will
  18434. - * actually run the softirq once we return from
  18435. - * the irq or softirq.
  18436. - *
  18437. - * Otherwise we wake up ksoftirqd to make sure we
  18438. - * schedule the softirq soon.
  18439. - */
  18440. - if (!in_interrupt())
  18441. - wakeup_softirqd();
  18442. -}
  18443. -
  18444. void raise_softirq(unsigned int nr)
  18445. {
  18446. unsigned long flags;
  18447. @@ -424,12 +818,6 @@
  18448. local_irq_restore(flags);
  18449. }
  18450. -void __raise_softirq_irqoff(unsigned int nr)
  18451. -{
  18452. - trace_softirq_raise(nr);
  18453. - or_softirq_pending(1UL << nr);
  18454. -}
  18455. -
  18456. void open_softirq(int nr, void (*action)(struct softirq_action *))
  18457. {
  18458. softirq_vec[nr].action = action;
  18459. @@ -446,15 +834,45 @@
  18460. static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec);
  18461. static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec);
  18462. +static void inline
  18463. +__tasklet_common_schedule(struct tasklet_struct *t, struct tasklet_head *head, unsigned int nr)
  18464. +{
  18465. + if (tasklet_trylock(t)) {
  18466. +again:
  18467. + /* We may have been preempted before tasklet_trylock
  18468. + * and __tasklet_action may have already run.
  18469. + * So double check the sched bit while the takslet
  18470. + * is locked before adding it to the list.
  18471. + */
  18472. + if (test_bit(TASKLET_STATE_SCHED, &t->state)) {
  18473. + t->next = NULL;
  18474. + *head->tail = t;
  18475. + head->tail = &(t->next);
  18476. + raise_softirq_irqoff(nr);
  18477. + tasklet_unlock(t);
  18478. + } else {
  18479. + /* This is subtle. If we hit the corner case above
  18480. + * It is possible that we get preempted right here,
  18481. + * and another task has successfully called
  18482. + * tasklet_schedule(), then this function, and
  18483. + * failed on the trylock. Thus we must be sure
  18484. + * before releasing the tasklet lock, that the
  18485. + * SCHED_BIT is clear. Otherwise the tasklet
  18486. + * may get its SCHED_BIT set, but not added to the
  18487. + * list
  18488. + */
  18489. + if (!tasklet_tryunlock(t))
  18490. + goto again;
  18491. + }
  18492. + }
  18493. +}
  18494. +
  18495. void __tasklet_schedule(struct tasklet_struct *t)
  18496. {
  18497. unsigned long flags;
  18498. local_irq_save(flags);
  18499. - t->next = NULL;
  18500. - *__this_cpu_read(tasklet_vec.tail) = t;
  18501. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  18502. - raise_softirq_irqoff(TASKLET_SOFTIRQ);
  18503. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_vec), TASKLET_SOFTIRQ);
  18504. local_irq_restore(flags);
  18505. }
  18506. EXPORT_SYMBOL(__tasklet_schedule);
  18507. @@ -464,10 +882,7 @@
  18508. unsigned long flags;
  18509. local_irq_save(flags);
  18510. - t->next = NULL;
  18511. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  18512. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  18513. - raise_softirq_irqoff(HI_SOFTIRQ);
  18514. + __tasklet_common_schedule(t, this_cpu_ptr(&tasklet_hi_vec), HI_SOFTIRQ);
  18515. local_irq_restore(flags);
  18516. }
  18517. EXPORT_SYMBOL(__tasklet_hi_schedule);
  18518. @@ -476,82 +891,122 @@
  18519. {
  18520. BUG_ON(!irqs_disabled());
  18521. - t->next = __this_cpu_read(tasklet_hi_vec.head);
  18522. - __this_cpu_write(tasklet_hi_vec.head, t);
  18523. - __raise_softirq_irqoff(HI_SOFTIRQ);
  18524. + __tasklet_hi_schedule(t);
  18525. }
  18526. EXPORT_SYMBOL(__tasklet_hi_schedule_first);
  18527. -static void tasklet_action(struct softirq_action *a)
  18528. +void tasklet_enable(struct tasklet_struct *t)
  18529. {
  18530. - struct tasklet_struct *list;
  18531. + if (!atomic_dec_and_test(&t->count))
  18532. + return;
  18533. + if (test_and_clear_bit(TASKLET_STATE_PENDING, &t->state))
  18534. + tasklet_schedule(t);
  18535. +}
  18536. +EXPORT_SYMBOL(tasklet_enable);
  18537. - local_irq_disable();
  18538. - list = __this_cpu_read(tasklet_vec.head);
  18539. - __this_cpu_write(tasklet_vec.head, NULL);
  18540. - __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  18541. - local_irq_enable();
  18542. +static void __tasklet_action(struct softirq_action *a,
  18543. + struct tasklet_struct *list)
  18544. +{
  18545. + int loops = 1000000;
  18546. while (list) {
  18547. struct tasklet_struct *t = list;
  18548. list = list->next;
  18549. - if (tasklet_trylock(t)) {
  18550. - if (!atomic_read(&t->count)) {
  18551. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  18552. - &t->state))
  18553. - BUG();
  18554. - t->func(t->data);
  18555. - tasklet_unlock(t);
  18556. - continue;
  18557. - }
  18558. - tasklet_unlock(t);
  18559. + /*
  18560. + * Should always succeed - after a tasklist got on the
  18561. + * list (after getting the SCHED bit set from 0 to 1),
  18562. + * nothing but the tasklet softirq it got queued to can
  18563. + * lock it:
  18564. + */
  18565. + if (!tasklet_trylock(t)) {
  18566. + WARN_ON(1);
  18567. + continue;
  18568. }
  18569. - local_irq_disable();
  18570. t->next = NULL;
  18571. - *__this_cpu_read(tasklet_vec.tail) = t;
  18572. - __this_cpu_write(tasklet_vec.tail, &(t->next));
  18573. - __raise_softirq_irqoff(TASKLET_SOFTIRQ);
  18574. - local_irq_enable();
  18575. +
  18576. + /*
  18577. + * If we cannot handle the tasklet because it's disabled,
  18578. + * mark it as pending. tasklet_enable() will later
  18579. + * re-schedule the tasklet.
  18580. + */
  18581. + if (unlikely(atomic_read(&t->count))) {
  18582. +out_disabled:
  18583. + /* implicit unlock: */
  18584. + wmb();
  18585. + t->state = TASKLET_STATEF_PENDING;
  18586. + continue;
  18587. + }
  18588. +
  18589. + /*
  18590. + * After this point on the tasklet might be rescheduled
  18591. + * on another CPU, but it can only be added to another
  18592. + * CPU's tasklet list if we unlock the tasklet (which we
  18593. + * dont do yet).
  18594. + */
  18595. + if (!test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  18596. + WARN_ON(1);
  18597. +
  18598. +again:
  18599. + t->func(t->data);
  18600. +
  18601. + /*
  18602. + * Try to unlock the tasklet. We must use cmpxchg, because
  18603. + * another CPU might have scheduled or disabled the tasklet.
  18604. + * We only allow the STATE_RUN -> 0 transition here.
  18605. + */
  18606. + while (!tasklet_tryunlock(t)) {
  18607. + /*
  18608. + * If it got disabled meanwhile, bail out:
  18609. + */
  18610. + if (atomic_read(&t->count))
  18611. + goto out_disabled;
  18612. + /*
  18613. + * If it got scheduled meanwhile, re-execute
  18614. + * the tasklet function:
  18615. + */
  18616. + if (test_and_clear_bit(TASKLET_STATE_SCHED, &t->state))
  18617. + goto again;
  18618. + if (!--loops) {
  18619. + printk("hm, tasklet state: %08lx\n", t->state);
  18620. + WARN_ON(1);
  18621. + tasklet_unlock(t);
  18622. + break;
  18623. + }
  18624. + }
  18625. }
  18626. }
  18627. +static void tasklet_action(struct softirq_action *a)
  18628. +{
  18629. + struct tasklet_struct *list;
  18630. +
  18631. + local_irq_disable();
  18632. +
  18633. + list = __this_cpu_read(tasklet_vec.head);
  18634. + __this_cpu_write(tasklet_vec.head, NULL);
  18635. + __this_cpu_write(tasklet_vec.tail, this_cpu_ptr(&tasklet_vec.head));
  18636. +
  18637. + local_irq_enable();
  18638. +
  18639. + __tasklet_action(a, list);
  18640. +}
  18641. +
  18642. static void tasklet_hi_action(struct softirq_action *a)
  18643. {
  18644. struct tasklet_struct *list;
  18645. local_irq_disable();
  18646. +
  18647. list = __this_cpu_read(tasklet_hi_vec.head);
  18648. __this_cpu_write(tasklet_hi_vec.head, NULL);
  18649. __this_cpu_write(tasklet_hi_vec.tail, this_cpu_ptr(&tasklet_hi_vec.head));
  18650. - local_irq_enable();
  18651. -
  18652. - while (list) {
  18653. - struct tasklet_struct *t = list;
  18654. -
  18655. - list = list->next;
  18656. - if (tasklet_trylock(t)) {
  18657. - if (!atomic_read(&t->count)) {
  18658. - if (!test_and_clear_bit(TASKLET_STATE_SCHED,
  18659. - &t->state))
  18660. - BUG();
  18661. - t->func(t->data);
  18662. - tasklet_unlock(t);
  18663. - continue;
  18664. - }
  18665. - tasklet_unlock(t);
  18666. - }
  18667. + local_irq_enable();
  18668. - local_irq_disable();
  18669. - t->next = NULL;
  18670. - *__this_cpu_read(tasklet_hi_vec.tail) = t;
  18671. - __this_cpu_write(tasklet_hi_vec.tail, &(t->next));
  18672. - __raise_softirq_irqoff(HI_SOFTIRQ);
  18673. - local_irq_enable();
  18674. - }
  18675. + __tasklet_action(a, list);
  18676. }
  18677. void tasklet_init(struct tasklet_struct *t,
  18678. @@ -572,7 +1027,7 @@
  18679. while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
  18680. do {
  18681. - yield();
  18682. + msleep(1);
  18683. } while (test_bit(TASKLET_STATE_SCHED, &t->state));
  18684. }
  18685. tasklet_unlock_wait(t);
  18686. @@ -646,25 +1101,26 @@
  18687. open_softirq(HI_SOFTIRQ, tasklet_hi_action);
  18688. }
  18689. -static int ksoftirqd_should_run(unsigned int cpu)
  18690. -{
  18691. - return local_softirq_pending();
  18692. -}
  18693. -
  18694. -static void run_ksoftirqd(unsigned int cpu)
  18695. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  18696. +void tasklet_unlock_wait(struct tasklet_struct *t)
  18697. {
  18698. - local_irq_disable();
  18699. - if (local_softirq_pending()) {
  18700. + while (test_bit(TASKLET_STATE_RUN, &(t)->state)) {
  18701. /*
  18702. - * We can safely run softirq on inline stack, as we are not deep
  18703. - * in the task stack here.
  18704. + * Hack for now to avoid this busy-loop:
  18705. */
  18706. - __do_softirq();
  18707. - local_irq_enable();
  18708. - cond_resched_rcu_qs();
  18709. - return;
  18710. +#ifdef CONFIG_PREEMPT_RT_FULL
  18711. + msleep(1);
  18712. +#else
  18713. + barrier();
  18714. +#endif
  18715. }
  18716. - local_irq_enable();
  18717. +}
  18718. +EXPORT_SYMBOL(tasklet_unlock_wait);
  18719. +#endif
  18720. +
  18721. +static int ksoftirqd_should_run(unsigned int cpu)
  18722. +{
  18723. + return ksoftirqd_softirq_pending();
  18724. }
  18725. #ifdef CONFIG_HOTPLUG_CPU
  18726. @@ -746,6 +1202,8 @@
  18727. static struct smp_hotplug_thread softirq_threads = {
  18728. .store = &ksoftirqd,
  18729. + .setup = ksoftirqd_set_sched_params,
  18730. + .cleanup = ksoftirqd_clr_sched_params,
  18731. .thread_should_run = ksoftirqd_should_run,
  18732. .thread_fn = run_ksoftirqd,
  18733. .thread_comm = "ksoftirqd/%u",
  18734. diff -Nur linux-4.1.6.orig/kernel/stop_machine.c linux-4.1.6/kernel/stop_machine.c
  18735. --- linux-4.1.6.orig/kernel/stop_machine.c 2015-08-17 05:52:51.000000000 +0200
  18736. +++ linux-4.1.6/kernel/stop_machine.c 2015-09-08 23:49:08.117866054 +0200
  18737. @@ -30,12 +30,12 @@
  18738. atomic_t nr_todo; /* nr left to execute */
  18739. bool executed; /* actually executed? */
  18740. int ret; /* collected return value */
  18741. - struct completion completion; /* fired if nr_todo reaches 0 */
  18742. + struct task_struct *waiter; /* woken when nr_todo reaches 0 */
  18743. };
  18744. /* the actual stopper, one per every possible cpu, enabled on online cpus */
  18745. struct cpu_stopper {
  18746. - spinlock_t lock;
  18747. + raw_spinlock_t lock;
  18748. bool enabled; /* is this stopper enabled? */
  18749. struct list_head works; /* list of pending works */
  18750. };
  18751. @@ -56,7 +56,7 @@
  18752. {
  18753. memset(done, 0, sizeof(*done));
  18754. atomic_set(&done->nr_todo, nr_todo);
  18755. - init_completion(&done->completion);
  18756. + done->waiter = current;
  18757. }
  18758. /* signal completion unless @done is NULL */
  18759. @@ -65,8 +65,10 @@
  18760. if (done) {
  18761. if (executed)
  18762. done->executed = true;
  18763. - if (atomic_dec_and_test(&done->nr_todo))
  18764. - complete(&done->completion);
  18765. + if (atomic_dec_and_test(&done->nr_todo)) {
  18766. + wake_up_process(done->waiter);
  18767. + done->waiter = NULL;
  18768. + }
  18769. }
  18770. }
  18771. @@ -78,7 +80,7 @@
  18772. unsigned long flags;
  18773. - spin_lock_irqsave(&stopper->lock, flags);
  18774. + raw_spin_lock_irqsave(&stopper->lock, flags);
  18775. if (stopper->enabled) {
  18776. list_add_tail(&work->list, &stopper->works);
  18777. @@ -86,7 +88,23 @@
  18778. } else
  18779. cpu_stop_signal_done(work->done, false);
  18780. - spin_unlock_irqrestore(&stopper->lock, flags);
  18781. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  18782. +}
  18783. +
  18784. +static void wait_for_stop_done(struct cpu_stop_done *done)
  18785. +{
  18786. + set_current_state(TASK_UNINTERRUPTIBLE);
  18787. + while (atomic_read(&done->nr_todo)) {
  18788. + schedule();
  18789. + set_current_state(TASK_UNINTERRUPTIBLE);
  18790. + }
  18791. + /*
  18792. + * We need to wait until cpu_stop_signal_done() has cleared
  18793. + * done->waiter.
  18794. + */
  18795. + while (done->waiter)
  18796. + cpu_relax();
  18797. + set_current_state(TASK_RUNNING);
  18798. }
  18799. /**
  18800. @@ -120,7 +138,7 @@
  18801. cpu_stop_init_done(&done, 1);
  18802. cpu_stop_queue_work(cpu, &work);
  18803. - wait_for_completion(&done.completion);
  18804. + wait_for_stop_done(&done);
  18805. return done.executed ? done.ret : -ENOENT;
  18806. }
  18807. @@ -248,7 +266,7 @@
  18808. struct irq_cpu_stop_queue_work_info call_args;
  18809. struct multi_stop_data msdata;
  18810. - preempt_disable();
  18811. + preempt_disable_nort();
  18812. msdata = (struct multi_stop_data){
  18813. .fn = fn,
  18814. .data = arg,
  18815. @@ -281,7 +299,7 @@
  18816. * This relies on the stopper workqueues to be FIFO.
  18817. */
  18818. if (!cpu_active(cpu1) || !cpu_active(cpu2)) {
  18819. - preempt_enable();
  18820. + preempt_enable_nort();
  18821. return -ENOENT;
  18822. }
  18823. @@ -295,9 +313,9 @@
  18824. &irq_cpu_stop_queue_work,
  18825. &call_args, 1);
  18826. lg_local_unlock(&stop_cpus_lock);
  18827. - preempt_enable();
  18828. + preempt_enable_nort();
  18829. - wait_for_completion(&done.completion);
  18830. + wait_for_stop_done(&done);
  18831. return done.executed ? done.ret : -ENOENT;
  18832. }
  18833. @@ -329,7 +347,7 @@
  18834. static void queue_stop_cpus_work(const struct cpumask *cpumask,
  18835. cpu_stop_fn_t fn, void *arg,
  18836. - struct cpu_stop_done *done)
  18837. + struct cpu_stop_done *done, bool inactive)
  18838. {
  18839. struct cpu_stop_work *work;
  18840. unsigned int cpu;
  18841. @@ -343,11 +361,13 @@
  18842. }
  18843. /*
  18844. - * Disable preemption while queueing to avoid getting
  18845. - * preempted by a stopper which might wait for other stoppers
  18846. - * to enter @fn which can lead to deadlock.
  18847. + * Make sure that all work is queued on all cpus before
  18848. + * any of the cpus can execute it.
  18849. */
  18850. - lg_global_lock(&stop_cpus_lock);
  18851. + if (!inactive)
  18852. + lg_global_lock(&stop_cpus_lock);
  18853. + else
  18854. + lg_global_trylock_relax(&stop_cpus_lock);
  18855. for_each_cpu(cpu, cpumask)
  18856. cpu_stop_queue_work(cpu, &per_cpu(stop_cpus_work, cpu));
  18857. lg_global_unlock(&stop_cpus_lock);
  18858. @@ -359,8 +379,8 @@
  18859. struct cpu_stop_done done;
  18860. cpu_stop_init_done(&done, cpumask_weight(cpumask));
  18861. - queue_stop_cpus_work(cpumask, fn, arg, &done);
  18862. - wait_for_completion(&done.completion);
  18863. + queue_stop_cpus_work(cpumask, fn, arg, &done, false);
  18864. + wait_for_stop_done(&done);
  18865. return done.executed ? done.ret : -ENOENT;
  18866. }
  18867. @@ -439,9 +459,9 @@
  18868. unsigned long flags;
  18869. int run;
  18870. - spin_lock_irqsave(&stopper->lock, flags);
  18871. + raw_spin_lock_irqsave(&stopper->lock, flags);
  18872. run = !list_empty(&stopper->works);
  18873. - spin_unlock_irqrestore(&stopper->lock, flags);
  18874. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  18875. return run;
  18876. }
  18877. @@ -453,13 +473,13 @@
  18878. repeat:
  18879. work = NULL;
  18880. - spin_lock_irq(&stopper->lock);
  18881. + raw_spin_lock_irq(&stopper->lock);
  18882. if (!list_empty(&stopper->works)) {
  18883. work = list_first_entry(&stopper->works,
  18884. struct cpu_stop_work, list);
  18885. list_del_init(&work->list);
  18886. }
  18887. - spin_unlock_irq(&stopper->lock);
  18888. + raw_spin_unlock_irq(&stopper->lock);
  18889. if (work) {
  18890. cpu_stop_fn_t fn = work->fn;
  18891. @@ -467,6 +487,16 @@
  18892. struct cpu_stop_done *done = work->done;
  18893. char ksym_buf[KSYM_NAME_LEN] __maybe_unused;
  18894. + /*
  18895. + * Wait until the stopper finished scheduling on all
  18896. + * cpus
  18897. + */
  18898. + lg_global_lock(&stop_cpus_lock);
  18899. + /*
  18900. + * Let other cpu threads continue as well
  18901. + */
  18902. + lg_global_unlock(&stop_cpus_lock);
  18903. +
  18904. /* cpu stop callbacks are not allowed to sleep */
  18905. preempt_disable();
  18906. @@ -481,7 +511,13 @@
  18907. kallsyms_lookup((unsigned long)fn, NULL, NULL, NULL,
  18908. ksym_buf), arg);
  18909. + /*
  18910. + * Make sure that the wakeup and setting done->waiter
  18911. + * to NULL is atomic.
  18912. + */
  18913. + local_irq_disable();
  18914. cpu_stop_signal_done(done, true);
  18915. + local_irq_enable();
  18916. goto repeat;
  18917. }
  18918. }
  18919. @@ -500,20 +536,20 @@
  18920. unsigned long flags;
  18921. /* drain remaining works */
  18922. - spin_lock_irqsave(&stopper->lock, flags);
  18923. + raw_spin_lock_irqsave(&stopper->lock, flags);
  18924. list_for_each_entry(work, &stopper->works, list)
  18925. cpu_stop_signal_done(work->done, false);
  18926. stopper->enabled = false;
  18927. - spin_unlock_irqrestore(&stopper->lock, flags);
  18928. + raw_spin_unlock_irqrestore(&stopper->lock, flags);
  18929. }
  18930. static void cpu_stop_unpark(unsigned int cpu)
  18931. {
  18932. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  18933. - spin_lock_irq(&stopper->lock);
  18934. + raw_spin_lock_irq(&stopper->lock);
  18935. stopper->enabled = true;
  18936. - spin_unlock_irq(&stopper->lock);
  18937. + raw_spin_unlock_irq(&stopper->lock);
  18938. }
  18939. static struct smp_hotplug_thread cpu_stop_threads = {
  18940. @@ -535,10 +571,12 @@
  18941. for_each_possible_cpu(cpu) {
  18942. struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
  18943. - spin_lock_init(&stopper->lock);
  18944. + raw_spin_lock_init(&stopper->lock);
  18945. INIT_LIST_HEAD(&stopper->works);
  18946. }
  18947. + lg_lock_init(&stop_cpus_lock, "stop_cpus_lock");
  18948. +
  18949. BUG_ON(smpboot_register_percpu_thread(&cpu_stop_threads));
  18950. stop_machine_initialized = true;
  18951. return 0;
  18952. @@ -634,11 +672,11 @@
  18953. set_state(&msdata, MULTI_STOP_PREPARE);
  18954. cpu_stop_init_done(&done, num_active_cpus());
  18955. queue_stop_cpus_work(cpu_active_mask, multi_cpu_stop, &msdata,
  18956. - &done);
  18957. + &done, true);
  18958. ret = multi_cpu_stop(&msdata);
  18959. /* Busy wait for completion. */
  18960. - while (!completion_done(&done.completion))
  18961. + while (atomic_read(&done.nr_todo))
  18962. cpu_relax();
  18963. mutex_unlock(&stop_cpus_mutex);
  18964. diff -Nur linux-4.1.6.orig/kernel/time/hrtimer.c linux-4.1.6/kernel/time/hrtimer.c
  18965. --- linux-4.1.6.orig/kernel/time/hrtimer.c 2015-08-17 05:52:51.000000000 +0200
  18966. +++ linux-4.1.6/kernel/time/hrtimer.c 2015-09-08 23:49:08.117866054 +0200
  18967. @@ -48,11 +48,13 @@
  18968. #include <linux/sched/rt.h>
  18969. #include <linux/sched/deadline.h>
  18970. #include <linux/timer.h>
  18971. +#include <linux/kthread.h>
  18972. #include <linux/freezer.h>
  18973. #include <asm/uaccess.h>
  18974. #include <trace/events/timer.h>
  18975. +#include <trace/events/hist.h>
  18976. #include "tick-internal.h"
  18977. @@ -576,8 +578,7 @@
  18978. * When the callback is running, we do not reprogram the clock event
  18979. * device. The timer callback is either running on a different CPU or
  18980. * the callback is executed in the hrtimer_interrupt context. The
  18981. - * reprogramming is handled either by the softirq, which called the
  18982. - * callback or at the end of the hrtimer_interrupt.
  18983. + * reprogramming is handled at the end of the hrtimer_interrupt.
  18984. */
  18985. if (hrtimer_callback_running(timer))
  18986. return 0;
  18987. @@ -621,6 +622,9 @@
  18988. return res;
  18989. }
  18990. +static void __run_hrtimer(struct hrtimer *timer, ktime_t *now);
  18991. +static int hrtimer_rt_defer(struct hrtimer *timer);
  18992. +
  18993. /*
  18994. * Initialize the high resolution related parts of cpu_base
  18995. */
  18996. @@ -630,6 +634,21 @@
  18997. base->hres_active = 0;
  18998. }
  18999. +static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  19000. + struct hrtimer_clock_base *base,
  19001. + int wakeup)
  19002. +{
  19003. + if (!hrtimer_reprogram(timer, base))
  19004. + return 0;
  19005. + if (!wakeup)
  19006. + return -ETIME;
  19007. +#ifdef CONFIG_PREEMPT_RT_BASE
  19008. + if (!hrtimer_rt_defer(timer))
  19009. + return -ETIME;
  19010. +#endif
  19011. + return 1;
  19012. +}
  19013. +
  19014. static inline ktime_t hrtimer_update_base(struct hrtimer_cpu_base *base)
  19015. {
  19016. ktime_t *offs_real = &base->clock_base[HRTIMER_BASE_REALTIME].offset;
  19017. @@ -695,6 +714,44 @@
  19018. static DECLARE_WORK(hrtimer_work, clock_was_set_work);
  19019. +#ifdef CONFIG_PREEMPT_RT_FULL
  19020. +/*
  19021. + * RT can not call schedule_work from real interrupt context.
  19022. + * Need to make a thread to do the real work.
  19023. + */
  19024. +static struct task_struct *clock_set_delay_thread;
  19025. +static bool do_clock_set_delay;
  19026. +
  19027. +static int run_clock_set_delay(void *ignore)
  19028. +{
  19029. + while (!kthread_should_stop()) {
  19030. + set_current_state(TASK_INTERRUPTIBLE);
  19031. + if (do_clock_set_delay) {
  19032. + do_clock_set_delay = false;
  19033. + schedule_work(&hrtimer_work);
  19034. + }
  19035. + schedule();
  19036. + }
  19037. + __set_current_state(TASK_RUNNING);
  19038. + return 0;
  19039. +}
  19040. +
  19041. +void clock_was_set_delayed(void)
  19042. +{
  19043. + do_clock_set_delay = true;
  19044. + /* Make visible before waking up process */
  19045. + smp_wmb();
  19046. + wake_up_process(clock_set_delay_thread);
  19047. +}
  19048. +
  19049. +static __init int create_clock_set_delay_thread(void)
  19050. +{
  19051. + clock_set_delay_thread = kthread_run(run_clock_set_delay, NULL, "kclksetdelayd");
  19052. + BUG_ON(!clock_set_delay_thread);
  19053. + return 0;
  19054. +}
  19055. +early_initcall(create_clock_set_delay_thread);
  19056. +#else /* PREEMPT_RT_FULL */
  19057. /*
  19058. * Called from timekeeping and resume code to reprogramm the hrtimer
  19059. * interrupt device on all cpus.
  19060. @@ -703,6 +760,7 @@
  19061. {
  19062. schedule_work(&hrtimer_work);
  19063. }
  19064. +#endif
  19065. #else
  19066. @@ -711,6 +769,13 @@
  19067. static inline int hrtimer_switch_to_hres(void) { return 0; }
  19068. static inline void
  19069. hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
  19070. +static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
  19071. + struct hrtimer_clock_base *base,
  19072. + int wakeup)
  19073. +{
  19074. + return 0;
  19075. +}
  19076. +
  19077. static inline int hrtimer_reprogram(struct hrtimer *timer,
  19078. struct hrtimer_clock_base *base)
  19079. {
  19080. @@ -718,7 +783,6 @@
  19081. }
  19082. static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
  19083. static inline void retrigger_next_event(void *arg) { }
  19084. -
  19085. #endif /* CONFIG_HIGH_RES_TIMERS */
  19086. /*
  19087. @@ -836,6 +900,32 @@
  19088. }
  19089. EXPORT_SYMBOL_GPL(hrtimer_forward);
  19090. +#ifdef CONFIG_PREEMPT_RT_BASE
  19091. +# define wake_up_timer_waiters(b) wake_up(&(b)->wait)
  19092. +
  19093. +/**
  19094. + * hrtimer_wait_for_timer - Wait for a running timer
  19095. + *
  19096. + * @timer: timer to wait for
  19097. + *
  19098. + * The function waits in case the timers callback function is
  19099. + * currently executed on the waitqueue of the timer base. The
  19100. + * waitqueue is woken up after the timer callback function has
  19101. + * finished execution.
  19102. + */
  19103. +void hrtimer_wait_for_timer(const struct hrtimer *timer)
  19104. +{
  19105. + struct hrtimer_clock_base *base = timer->base;
  19106. +
  19107. + if (base && base->cpu_base && !timer->irqsafe)
  19108. + wait_event(base->cpu_base->wait,
  19109. + !(timer->state & HRTIMER_STATE_CALLBACK));
  19110. +}
  19111. +
  19112. +#else
  19113. +# define wake_up_timer_waiters(b) do { } while (0)
  19114. +#endif
  19115. +
  19116. /*
  19117. * enqueue_hrtimer - internal function to (re)start a timer
  19118. *
  19119. @@ -879,6 +969,11 @@
  19120. if (!(timer->state & HRTIMER_STATE_ENQUEUED))
  19121. goto out;
  19122. + if (unlikely(!list_empty(&timer->cb_entry))) {
  19123. + list_del_init(&timer->cb_entry);
  19124. + goto out;
  19125. + }
  19126. +
  19127. next_timer = timerqueue_getnext(&base->active);
  19128. timerqueue_del(&base->active, &timer->node);
  19129. if (&timer->node == next_timer) {
  19130. @@ -966,7 +1061,16 @@
  19131. new_base = switch_hrtimer_base(timer, base, mode & HRTIMER_MODE_PINNED);
  19132. timer_stats_hrtimer_set_start_info(timer);
  19133. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  19134. + {
  19135. + ktime_t now = new_base->get_time();
  19136. + if (ktime_to_ns(tim) < ktime_to_ns(now))
  19137. + timer->praecox = now;
  19138. + else
  19139. + timer->praecox = ktime_set(0, 0);
  19140. + }
  19141. +#endif
  19142. leftmost = enqueue_hrtimer(timer, new_base);
  19143. if (!leftmost) {
  19144. @@ -980,15 +1084,26 @@
  19145. * on dynticks target.
  19146. */
  19147. wake_up_nohz_cpu(new_base->cpu_base->cpu);
  19148. - } else if (new_base->cpu_base == this_cpu_ptr(&hrtimer_bases) &&
  19149. - hrtimer_reprogram(timer, new_base)) {
  19150. + } else if (new_base->cpu_base == this_cpu_ptr(&hrtimer_bases)) {
  19151. +
  19152. + ret = hrtimer_enqueue_reprogram(timer, new_base, wakeup);
  19153. + if (ret < 0) {
  19154. + /*
  19155. + * In case we failed to reprogram the timer (mostly
  19156. + * because out current timer is already elapsed),
  19157. + * remove it again and report a failure. This avoids
  19158. + * stale base->first entries.
  19159. + */
  19160. + debug_deactivate(timer);
  19161. + __remove_hrtimer(timer, new_base,
  19162. + timer->state & HRTIMER_STATE_CALLBACK, 0);
  19163. + } else if (ret > 0) {
  19164. /*
  19165. * Only allow reprogramming if the new base is on this CPU.
  19166. * (it might still be on another CPU if the timer was pending)
  19167. *
  19168. * XXX send_remote_softirq() ?
  19169. */
  19170. - if (wakeup) {
  19171. /*
  19172. * We need to drop cpu_base->lock to avoid a
  19173. * lock ordering issue vs. rq->lock.
  19174. @@ -996,9 +1111,7 @@
  19175. raw_spin_unlock(&new_base->cpu_base->lock);
  19176. raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  19177. local_irq_restore(flags);
  19178. - return ret;
  19179. - } else {
  19180. - __raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  19181. + return 0;
  19182. }
  19183. }
  19184. @@ -1089,7 +1202,7 @@
  19185. if (ret >= 0)
  19186. return ret;
  19187. - cpu_relax();
  19188. + hrtimer_wait_for_timer(timer);
  19189. }
  19190. }
  19191. EXPORT_SYMBOL_GPL(hrtimer_cancel);
  19192. @@ -1153,6 +1266,7 @@
  19193. base = hrtimer_clockid_to_base(clock_id);
  19194. timer->base = &cpu_base->clock_base[base];
  19195. + INIT_LIST_HEAD(&timer->cb_entry);
  19196. timerqueue_init(&timer->node);
  19197. #ifdef CONFIG_TIMER_STATS
  19198. @@ -1236,6 +1350,126 @@
  19199. timer->state &= ~HRTIMER_STATE_CALLBACK;
  19200. }
  19201. +static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
  19202. +
  19203. +#ifdef CONFIG_PREEMPT_RT_BASE
  19204. +static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
  19205. + struct hrtimer_clock_base *base)
  19206. +{
  19207. + /*
  19208. + * Note, we clear the callback flag before we requeue the
  19209. + * timer otherwise we trigger the callback_running() check
  19210. + * in hrtimer_reprogram().
  19211. + */
  19212. + timer->state &= ~HRTIMER_STATE_CALLBACK;
  19213. +
  19214. + if (restart != HRTIMER_NORESTART) {
  19215. + BUG_ON(hrtimer_active(timer));
  19216. + /*
  19217. + * Enqueue the timer, if it's the leftmost timer then
  19218. + * we need to reprogram it.
  19219. + */
  19220. + if (!enqueue_hrtimer(timer, base))
  19221. + return;
  19222. +
  19223. +#ifndef CONFIG_HIGH_RES_TIMERS
  19224. + }
  19225. +#else
  19226. + if (base->cpu_base->hres_active &&
  19227. + hrtimer_reprogram(timer, base))
  19228. + goto requeue;
  19229. +
  19230. + } else if (hrtimer_active(timer)) {
  19231. + /*
  19232. + * If the timer was rearmed on another CPU, reprogram
  19233. + * the event device.
  19234. + */
  19235. + if (&timer->node == base->active.next &&
  19236. + base->cpu_base->hres_active &&
  19237. + hrtimer_reprogram(timer, base))
  19238. + goto requeue;
  19239. + }
  19240. + return;
  19241. +
  19242. +requeue:
  19243. + /*
  19244. + * Timer is expired. Thus move it from tree to pending list
  19245. + * again.
  19246. + */
  19247. + __remove_hrtimer(timer, base, timer->state, 0);
  19248. + list_add_tail(&timer->cb_entry, &base->expired);
  19249. +#endif
  19250. +}
  19251. +
  19252. +/*
  19253. + * The changes in mainline which removed the callback modes from
  19254. + * hrtimer are not yet working with -rt. The non wakeup_process()
  19255. + * based callbacks which involve sleeping locks need to be treated
  19256. + * seperately.
  19257. + */
  19258. +static void hrtimer_rt_run_pending(void)
  19259. +{
  19260. + enum hrtimer_restart (*fn)(struct hrtimer *);
  19261. + struct hrtimer_cpu_base *cpu_base;
  19262. + struct hrtimer_clock_base *base;
  19263. + struct hrtimer *timer;
  19264. + int index, restart;
  19265. +
  19266. + local_irq_disable();
  19267. + cpu_base = &per_cpu(hrtimer_bases, smp_processor_id());
  19268. +
  19269. + raw_spin_lock(&cpu_base->lock);
  19270. +
  19271. + for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
  19272. + base = &cpu_base->clock_base[index];
  19273. +
  19274. + while (!list_empty(&base->expired)) {
  19275. + timer = list_first_entry(&base->expired,
  19276. + struct hrtimer, cb_entry);
  19277. +
  19278. + /*
  19279. + * Same as the above __run_hrtimer function
  19280. + * just we run with interrupts enabled.
  19281. + */
  19282. + debug_hrtimer_deactivate(timer);
  19283. + __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
  19284. + timer_stats_account_hrtimer(timer);
  19285. + fn = timer->function;
  19286. +
  19287. + raw_spin_unlock_irq(&cpu_base->lock);
  19288. + restart = fn(timer);
  19289. + raw_spin_lock_irq(&cpu_base->lock);
  19290. +
  19291. + hrtimer_rt_reprogram(restart, timer, base);
  19292. + }
  19293. + }
  19294. +
  19295. + raw_spin_unlock_irq(&cpu_base->lock);
  19296. +
  19297. + wake_up_timer_waiters(cpu_base);
  19298. +}
  19299. +
  19300. +static int hrtimer_rt_defer(struct hrtimer *timer)
  19301. +{
  19302. + if (timer->irqsafe)
  19303. + return 0;
  19304. +
  19305. + __remove_hrtimer(timer, timer->base, timer->state, 0);
  19306. + list_add_tail(&timer->cb_entry, &timer->base->expired);
  19307. + return 1;
  19308. +}
  19309. +
  19310. +#else
  19311. +
  19312. +static inline void hrtimer_rt_run_pending(void)
  19313. +{
  19314. + hrtimer_peek_ahead_timers();
  19315. +}
  19316. +
  19317. +static inline int hrtimer_rt_defer(struct hrtimer *timer) { return 0; }
  19318. +
  19319. +#endif
  19320. +
  19321. #ifdef CONFIG_HIGH_RES_TIMERS
  19322. /*
  19323. @@ -1246,7 +1480,7 @@
  19324. {
  19325. struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
  19326. ktime_t expires_next, now, entry_time, delta;
  19327. - int i, retries = 0;
  19328. + int i, retries = 0, raise = 0;
  19329. BUG_ON(!cpu_base->hres_active);
  19330. cpu_base->nr_events++;
  19331. @@ -1281,6 +1515,15 @@
  19332. timer = container_of(node, struct hrtimer, node);
  19333. + trace_hrtimer_interrupt(raw_smp_processor_id(),
  19334. + ktime_to_ns(ktime_sub(ktime_to_ns(timer->praecox) ?
  19335. + timer->praecox : hrtimer_get_expires(timer),
  19336. + basenow)),
  19337. + current,
  19338. + timer->function == hrtimer_wakeup ?
  19339. + container_of(timer, struct hrtimer_sleeper,
  19340. + timer)->task : NULL);
  19341. +
  19342. /*
  19343. * The immediate goal for using the softexpires is
  19344. * minimizing wakeups, not running timers at the
  19345. @@ -1296,7 +1539,10 @@
  19346. if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer))
  19347. break;
  19348. - __run_hrtimer(timer, &basenow);
  19349. + if (!hrtimer_rt_defer(timer))
  19350. + __run_hrtimer(timer, &basenow);
  19351. + else
  19352. + raise = 1;
  19353. }
  19354. }
  19355. /* Reevaluate the clock bases for the next expiry */
  19356. @@ -1313,7 +1559,7 @@
  19357. if (expires_next.tv64 == KTIME_MAX ||
  19358. !tick_program_event(expires_next, 0)) {
  19359. cpu_base->hang_detected = 0;
  19360. - return;
  19361. + goto out;
  19362. }
  19363. /*
  19364. @@ -1357,6 +1603,9 @@
  19365. tick_program_event(expires_next, 1);
  19366. printk_once(KERN_WARNING "hrtimer: interrupt took %llu ns\n",
  19367. ktime_to_ns(delta));
  19368. +out:
  19369. + if (raise)
  19370. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  19371. }
  19372. /*
  19373. @@ -1392,18 +1641,18 @@
  19374. __hrtimer_peek_ahead_timers();
  19375. local_irq_restore(flags);
  19376. }
  19377. -
  19378. -static void run_hrtimer_softirq(struct softirq_action *h)
  19379. -{
  19380. - hrtimer_peek_ahead_timers();
  19381. -}
  19382. -
  19383. #else /* CONFIG_HIGH_RES_TIMERS */
  19384. static inline void __hrtimer_peek_ahead_timers(void) { }
  19385. #endif /* !CONFIG_HIGH_RES_TIMERS */
  19386. +
  19387. +static void run_hrtimer_softirq(struct softirq_action *h)
  19388. +{
  19389. + hrtimer_rt_run_pending();
  19390. +}
  19391. +
  19392. /*
  19393. * Called from timer softirq every jiffy, expire hrtimers:
  19394. *
  19395. @@ -1436,7 +1685,7 @@
  19396. struct timerqueue_node *node;
  19397. struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
  19398. struct hrtimer_clock_base *base;
  19399. - int index, gettime = 1;
  19400. + int index, gettime = 1, raise = 0;
  19401. if (hrtimer_hres_active())
  19402. return;
  19403. @@ -1461,10 +1710,16 @@
  19404. hrtimer_get_expires_tv64(timer))
  19405. break;
  19406. - __run_hrtimer(timer, &base->softirq_time);
  19407. + if (!hrtimer_rt_defer(timer))
  19408. + __run_hrtimer(timer, &base->softirq_time);
  19409. + else
  19410. + raise = 1;
  19411. }
  19412. raw_spin_unlock(&cpu_base->lock);
  19413. }
  19414. +
  19415. + if (raise)
  19416. + raise_softirq_irqoff(HRTIMER_SOFTIRQ);
  19417. }
  19418. /*
  19419. @@ -1486,16 +1741,18 @@
  19420. void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
  19421. {
  19422. sl->timer.function = hrtimer_wakeup;
  19423. + sl->timer.irqsafe = 1;
  19424. sl->task = task;
  19425. }
  19426. EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
  19427. -static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode)
  19428. +static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode,
  19429. + unsigned long state)
  19430. {
  19431. hrtimer_init_sleeper(t, current);
  19432. do {
  19433. - set_current_state(TASK_INTERRUPTIBLE);
  19434. + set_current_state(state);
  19435. hrtimer_start_expires(&t->timer, mode);
  19436. if (!hrtimer_active(&t->timer))
  19437. t->task = NULL;
  19438. @@ -1539,7 +1796,8 @@
  19439. HRTIMER_MODE_ABS);
  19440. hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
  19441. - if (do_nanosleep(&t, HRTIMER_MODE_ABS))
  19442. + /* cpu_chill() does not care about restart state. */
  19443. + if (do_nanosleep(&t, HRTIMER_MODE_ABS, TASK_INTERRUPTIBLE))
  19444. goto out;
  19445. rmtp = restart->nanosleep.rmtp;
  19446. @@ -1556,8 +1814,10 @@
  19447. return ret;
  19448. }
  19449. -long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  19450. - const enum hrtimer_mode mode, const clockid_t clockid)
  19451. +static long
  19452. +__hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  19453. + const enum hrtimer_mode mode, const clockid_t clockid,
  19454. + unsigned long state)
  19455. {
  19456. struct restart_block *restart;
  19457. struct hrtimer_sleeper t;
  19458. @@ -1570,7 +1830,7 @@
  19459. hrtimer_init_on_stack(&t.timer, clockid, mode);
  19460. hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack);
  19461. - if (do_nanosleep(&t, mode))
  19462. + if (do_nanosleep(&t, mode, state))
  19463. goto out;
  19464. /* Absolute timers do not update the rmtp value and restart: */
  19465. @@ -1597,6 +1857,12 @@
  19466. return ret;
  19467. }
  19468. +long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp,
  19469. + const enum hrtimer_mode mode, const clockid_t clockid)
  19470. +{
  19471. + return __hrtimer_nanosleep(rqtp, rmtp, mode, clockid, TASK_INTERRUPTIBLE);
  19472. +}
  19473. +
  19474. SYSCALL_DEFINE2(nanosleep, struct timespec __user *, rqtp,
  19475. struct timespec __user *, rmtp)
  19476. {
  19477. @@ -1611,6 +1877,26 @@
  19478. return hrtimer_nanosleep(&tu, rmtp, HRTIMER_MODE_REL, CLOCK_MONOTONIC);
  19479. }
  19480. +#ifdef CONFIG_PREEMPT_RT_FULL
  19481. +/*
  19482. + * Sleep for 1 ms in hope whoever holds what we want will let it go.
  19483. + */
  19484. +void cpu_chill(void)
  19485. +{
  19486. + struct timespec tu = {
  19487. + .tv_nsec = NSEC_PER_MSEC,
  19488. + };
  19489. + unsigned int freeze_flag = current->flags & PF_NOFREEZE;
  19490. +
  19491. + current->flags |= PF_NOFREEZE;
  19492. + __hrtimer_nanosleep(&tu, NULL, HRTIMER_MODE_REL, CLOCK_MONOTONIC,
  19493. + TASK_UNINTERRUPTIBLE);
  19494. + if (!freeze_flag)
  19495. + current->flags &= ~PF_NOFREEZE;
  19496. +}
  19497. +EXPORT_SYMBOL(cpu_chill);
  19498. +#endif
  19499. +
  19500. /*
  19501. * Functions related to boot-time initialization:
  19502. */
  19503. @@ -1622,10 +1908,14 @@
  19504. for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
  19505. cpu_base->clock_base[i].cpu_base = cpu_base;
  19506. timerqueue_init_head(&cpu_base->clock_base[i].active);
  19507. + INIT_LIST_HEAD(&cpu_base->clock_base[i].expired);
  19508. }
  19509. cpu_base->cpu = cpu;
  19510. hrtimer_init_hres(cpu_base);
  19511. +#ifdef CONFIG_PREEMPT_RT_BASE
  19512. + init_waitqueue_head(&cpu_base->wait);
  19513. +#endif
  19514. }
  19515. #ifdef CONFIG_HOTPLUG_CPU
  19516. @@ -1731,9 +2021,7 @@
  19517. hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
  19518. (void *)(long)smp_processor_id());
  19519. register_cpu_notifier(&hrtimers_nb);
  19520. -#ifdef CONFIG_HIGH_RES_TIMERS
  19521. open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
  19522. -#endif
  19523. }
  19524. /**
  19525. diff -Nur linux-4.1.6.orig/kernel/time/itimer.c linux-4.1.6/kernel/time/itimer.c
  19526. --- linux-4.1.6.orig/kernel/time/itimer.c 2015-08-17 05:52:51.000000000 +0200
  19527. +++ linux-4.1.6/kernel/time/itimer.c 2015-09-08 23:49:08.117866054 +0200
  19528. @@ -213,6 +213,7 @@
  19529. /* We are sharing ->siglock with it_real_fn() */
  19530. if (hrtimer_try_to_cancel(timer) < 0) {
  19531. spin_unlock_irq(&tsk->sighand->siglock);
  19532. + hrtimer_wait_for_timer(&tsk->signal->real_timer);
  19533. goto again;
  19534. }
  19535. expires = timeval_to_ktime(value->it_value);
  19536. diff -Nur linux-4.1.6.orig/kernel/time/jiffies.c linux-4.1.6/kernel/time/jiffies.c
  19537. --- linux-4.1.6.orig/kernel/time/jiffies.c 2015-08-17 05:52:51.000000000 +0200
  19538. +++ linux-4.1.6/kernel/time/jiffies.c 2015-09-08 23:49:08.117866054 +0200
  19539. @@ -74,7 +74,8 @@
  19540. .max_cycles = 10,
  19541. };
  19542. -__cacheline_aligned_in_smp DEFINE_SEQLOCK(jiffies_lock);
  19543. +__cacheline_aligned_in_smp DEFINE_RAW_SPINLOCK(jiffies_lock);
  19544. +__cacheline_aligned_in_smp seqcount_t jiffies_seq;
  19545. #if (BITS_PER_LONG < 64)
  19546. u64 get_jiffies_64(void)
  19547. @@ -83,9 +84,9 @@
  19548. u64 ret;
  19549. do {
  19550. - seq = read_seqbegin(&jiffies_lock);
  19551. + seq = read_seqcount_begin(&jiffies_seq);
  19552. ret = jiffies_64;
  19553. - } while (read_seqretry(&jiffies_lock, seq));
  19554. + } while (read_seqcount_retry(&jiffies_seq, seq));
  19555. return ret;
  19556. }
  19557. EXPORT_SYMBOL(get_jiffies_64);
  19558. diff -Nur linux-4.1.6.orig/kernel/time/ntp.c linux-4.1.6/kernel/time/ntp.c
  19559. --- linux-4.1.6.orig/kernel/time/ntp.c 2015-08-17 05:52:51.000000000 +0200
  19560. +++ linux-4.1.6/kernel/time/ntp.c 2015-09-08 23:49:08.117866054 +0200
  19561. @@ -10,6 +10,7 @@
  19562. #include <linux/workqueue.h>
  19563. #include <linux/hrtimer.h>
  19564. #include <linux/jiffies.h>
  19565. +#include <linux/kthread.h>
  19566. #include <linux/math64.h>
  19567. #include <linux/timex.h>
  19568. #include <linux/time.h>
  19569. @@ -529,10 +530,52 @@
  19570. &sync_cmos_work, timespec_to_jiffies(&next));
  19571. }
  19572. +#ifdef CONFIG_PREEMPT_RT_FULL
  19573. +/*
  19574. + * RT can not call schedule_delayed_work from real interrupt context.
  19575. + * Need to make a thread to do the real work.
  19576. + */
  19577. +static struct task_struct *cmos_delay_thread;
  19578. +static bool do_cmos_delay;
  19579. +
  19580. +static int run_cmos_delay(void *ignore)
  19581. +{
  19582. + while (!kthread_should_stop()) {
  19583. + set_current_state(TASK_INTERRUPTIBLE);
  19584. + if (do_cmos_delay) {
  19585. + do_cmos_delay = false;
  19586. + queue_delayed_work(system_power_efficient_wq,
  19587. + &sync_cmos_work, 0);
  19588. + }
  19589. + schedule();
  19590. + }
  19591. + __set_current_state(TASK_RUNNING);
  19592. + return 0;
  19593. +}
  19594. +
  19595. +void ntp_notify_cmos_timer(void)
  19596. +{
  19597. + do_cmos_delay = true;
  19598. + /* Make visible before waking up process */
  19599. + smp_wmb();
  19600. + wake_up_process(cmos_delay_thread);
  19601. +}
  19602. +
  19603. +static __init int create_cmos_delay_thread(void)
  19604. +{
  19605. + cmos_delay_thread = kthread_run(run_cmos_delay, NULL, "kcmosdelayd");
  19606. + BUG_ON(!cmos_delay_thread);
  19607. + return 0;
  19608. +}
  19609. +early_initcall(create_cmos_delay_thread);
  19610. +
  19611. +#else
  19612. +
  19613. void ntp_notify_cmos_timer(void)
  19614. {
  19615. queue_delayed_work(system_power_efficient_wq, &sync_cmos_work, 0);
  19616. }
  19617. +#endif /* CONFIG_PREEMPT_RT_FULL */
  19618. #else
  19619. void ntp_notify_cmos_timer(void) { }
  19620. diff -Nur linux-4.1.6.orig/kernel/time/posix-cpu-timers.c linux-4.1.6/kernel/time/posix-cpu-timers.c
  19621. --- linux-4.1.6.orig/kernel/time/posix-cpu-timers.c 2015-08-17 05:52:51.000000000 +0200
  19622. +++ linux-4.1.6/kernel/time/posix-cpu-timers.c 2015-09-08 23:49:08.117866054 +0200
  19623. @@ -3,6 +3,7 @@
  19624. */
  19625. #include <linux/sched.h>
  19626. +#include <linux/sched/rt.h>
  19627. #include <linux/posix-timers.h>
  19628. #include <linux/errno.h>
  19629. #include <linux/math64.h>
  19630. @@ -626,7 +627,7 @@
  19631. /*
  19632. * Disarm any old timer after extracting its expiry time.
  19633. */
  19634. - WARN_ON_ONCE(!irqs_disabled());
  19635. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  19636. ret = 0;
  19637. old_incr = timer->it.cpu.incr;
  19638. @@ -1047,7 +1048,7 @@
  19639. /*
  19640. * Now re-arm for the new expiry time.
  19641. */
  19642. - WARN_ON_ONCE(!irqs_disabled());
  19643. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  19644. arm_timer(timer);
  19645. unlock_task_sighand(p, &flags);
  19646. @@ -1113,10 +1114,11 @@
  19647. sig = tsk->signal;
  19648. if (sig->cputimer.running) {
  19649. struct task_cputime group_sample;
  19650. + unsigned long flags;
  19651. - raw_spin_lock(&sig->cputimer.lock);
  19652. + raw_spin_lock_irqsave(&sig->cputimer.lock, flags);
  19653. group_sample = sig->cputimer.cputime;
  19654. - raw_spin_unlock(&sig->cputimer.lock);
  19655. + raw_spin_unlock_irqrestore(&sig->cputimer.lock, flags);
  19656. if (task_cputime_expired(&group_sample, &sig->cputime_expires))
  19657. return 1;
  19658. @@ -1130,13 +1132,13 @@
  19659. * already updated our counts. We need to check if any timers fire now.
  19660. * Interrupts are disabled.
  19661. */
  19662. -void run_posix_cpu_timers(struct task_struct *tsk)
  19663. +static void __run_posix_cpu_timers(struct task_struct *tsk)
  19664. {
  19665. LIST_HEAD(firing);
  19666. struct k_itimer *timer, *next;
  19667. unsigned long flags;
  19668. - WARN_ON_ONCE(!irqs_disabled());
  19669. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  19670. /*
  19671. * The fast path checks that there are no expired thread or thread
  19672. @@ -1194,6 +1196,190 @@
  19673. }
  19674. }
  19675. +#ifdef CONFIG_PREEMPT_RT_BASE
  19676. +#include <linux/kthread.h>
  19677. +#include <linux/cpu.h>
  19678. +DEFINE_PER_CPU(struct task_struct *, posix_timer_task);
  19679. +DEFINE_PER_CPU(struct task_struct *, posix_timer_tasklist);
  19680. +
  19681. +static int posix_cpu_timers_thread(void *data)
  19682. +{
  19683. + int cpu = (long)data;
  19684. +
  19685. + BUG_ON(per_cpu(posix_timer_task,cpu) != current);
  19686. +
  19687. + while (!kthread_should_stop()) {
  19688. + struct task_struct *tsk = NULL;
  19689. + struct task_struct *next = NULL;
  19690. +
  19691. + if (cpu_is_offline(cpu))
  19692. + goto wait_to_die;
  19693. +
  19694. + /* grab task list */
  19695. + raw_local_irq_disable();
  19696. + tsk = per_cpu(posix_timer_tasklist, cpu);
  19697. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  19698. + raw_local_irq_enable();
  19699. +
  19700. + /* its possible the list is empty, just return */
  19701. + if (!tsk) {
  19702. + set_current_state(TASK_INTERRUPTIBLE);
  19703. + schedule();
  19704. + __set_current_state(TASK_RUNNING);
  19705. + continue;
  19706. + }
  19707. +
  19708. + /* Process task list */
  19709. + while (1) {
  19710. + /* save next */
  19711. + next = tsk->posix_timer_list;
  19712. +
  19713. + /* run the task timers, clear its ptr and
  19714. + * unreference it
  19715. + */
  19716. + __run_posix_cpu_timers(tsk);
  19717. + tsk->posix_timer_list = NULL;
  19718. + put_task_struct(tsk);
  19719. +
  19720. + /* check if this is the last on the list */
  19721. + if (next == tsk)
  19722. + break;
  19723. + tsk = next;
  19724. + }
  19725. + }
  19726. + return 0;
  19727. +
  19728. +wait_to_die:
  19729. + /* Wait for kthread_stop */
  19730. + set_current_state(TASK_INTERRUPTIBLE);
  19731. + while (!kthread_should_stop()) {
  19732. + schedule();
  19733. + set_current_state(TASK_INTERRUPTIBLE);
  19734. + }
  19735. + __set_current_state(TASK_RUNNING);
  19736. + return 0;
  19737. +}
  19738. +
  19739. +static inline int __fastpath_timer_check(struct task_struct *tsk)
  19740. +{
  19741. + /* tsk == current, ensure it is safe to use ->signal/sighand */
  19742. + if (unlikely(tsk->exit_state))
  19743. + return 0;
  19744. +
  19745. + if (!task_cputime_zero(&tsk->cputime_expires))
  19746. + return 1;
  19747. +
  19748. + if (!task_cputime_zero(&tsk->signal->cputime_expires))
  19749. + return 1;
  19750. +
  19751. + return 0;
  19752. +}
  19753. +
  19754. +void run_posix_cpu_timers(struct task_struct *tsk)
  19755. +{
  19756. + unsigned long cpu = smp_processor_id();
  19757. + struct task_struct *tasklist;
  19758. +
  19759. + BUG_ON(!irqs_disabled());
  19760. + if(!per_cpu(posix_timer_task, cpu))
  19761. + return;
  19762. + /* get per-cpu references */
  19763. + tasklist = per_cpu(posix_timer_tasklist, cpu);
  19764. +
  19765. + /* check to see if we're already queued */
  19766. + if (!tsk->posix_timer_list && __fastpath_timer_check(tsk)) {
  19767. + get_task_struct(tsk);
  19768. + if (tasklist) {
  19769. + tsk->posix_timer_list = tasklist;
  19770. + } else {
  19771. + /*
  19772. + * The list is terminated by a self-pointing
  19773. + * task_struct
  19774. + */
  19775. + tsk->posix_timer_list = tsk;
  19776. + }
  19777. + per_cpu(posix_timer_tasklist, cpu) = tsk;
  19778. +
  19779. + wake_up_process(per_cpu(posix_timer_task, cpu));
  19780. + }
  19781. +}
  19782. +
  19783. +/*
  19784. + * posix_cpu_thread_call - callback that gets triggered when a CPU is added.
  19785. + * Here we can start up the necessary migration thread for the new CPU.
  19786. + */
  19787. +static int posix_cpu_thread_call(struct notifier_block *nfb,
  19788. + unsigned long action, void *hcpu)
  19789. +{
  19790. + int cpu = (long)hcpu;
  19791. + struct task_struct *p;
  19792. + struct sched_param param;
  19793. +
  19794. + switch (action) {
  19795. + case CPU_UP_PREPARE:
  19796. + p = kthread_create(posix_cpu_timers_thread, hcpu,
  19797. + "posixcputmr/%d",cpu);
  19798. + if (IS_ERR(p))
  19799. + return NOTIFY_BAD;
  19800. + p->flags |= PF_NOFREEZE;
  19801. + kthread_bind(p, cpu);
  19802. + /* Must be high prio to avoid getting starved */
  19803. + param.sched_priority = MAX_RT_PRIO-1;
  19804. + sched_setscheduler(p, SCHED_FIFO, &param);
  19805. + per_cpu(posix_timer_task,cpu) = p;
  19806. + break;
  19807. + case CPU_ONLINE:
  19808. + /* Strictly unneccessary, as first user will wake it. */
  19809. + wake_up_process(per_cpu(posix_timer_task,cpu));
  19810. + break;
  19811. +#ifdef CONFIG_HOTPLUG_CPU
  19812. + case CPU_UP_CANCELED:
  19813. + /* Unbind it from offline cpu so it can run. Fall thru. */
  19814. + kthread_bind(per_cpu(posix_timer_task, cpu),
  19815. + cpumask_any(cpu_online_mask));
  19816. + kthread_stop(per_cpu(posix_timer_task,cpu));
  19817. + per_cpu(posix_timer_task,cpu) = NULL;
  19818. + break;
  19819. + case CPU_DEAD:
  19820. + kthread_stop(per_cpu(posix_timer_task,cpu));
  19821. + per_cpu(posix_timer_task,cpu) = NULL;
  19822. + break;
  19823. +#endif
  19824. + }
  19825. + return NOTIFY_OK;
  19826. +}
  19827. +
  19828. +/* Register at highest priority so that task migration (migrate_all_tasks)
  19829. + * happens before everything else.
  19830. + */
  19831. +static struct notifier_block posix_cpu_thread_notifier = {
  19832. + .notifier_call = posix_cpu_thread_call,
  19833. + .priority = 10
  19834. +};
  19835. +
  19836. +static int __init posix_cpu_thread_init(void)
  19837. +{
  19838. + void *hcpu = (void *)(long)smp_processor_id();
  19839. + /* Start one for boot CPU. */
  19840. + unsigned long cpu;
  19841. +
  19842. + /* init the per-cpu posix_timer_tasklets */
  19843. + for_each_possible_cpu(cpu)
  19844. + per_cpu(posix_timer_tasklist, cpu) = NULL;
  19845. +
  19846. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_UP_PREPARE, hcpu);
  19847. + posix_cpu_thread_call(&posix_cpu_thread_notifier, CPU_ONLINE, hcpu);
  19848. + register_cpu_notifier(&posix_cpu_thread_notifier);
  19849. + return 0;
  19850. +}
  19851. +early_initcall(posix_cpu_thread_init);
  19852. +#else /* CONFIG_PREEMPT_RT_BASE */
  19853. +void run_posix_cpu_timers(struct task_struct *tsk)
  19854. +{
  19855. + __run_posix_cpu_timers(tsk);
  19856. +}
  19857. +#endif /* CONFIG_PREEMPT_RT_BASE */
  19858. +
  19859. /*
  19860. * Set one of the process-wide special case CPU timers or RLIMIT_CPU.
  19861. * The tsk->sighand->siglock must be held by the caller.
  19862. diff -Nur linux-4.1.6.orig/kernel/time/posix-timers.c linux-4.1.6/kernel/time/posix-timers.c
  19863. --- linux-4.1.6.orig/kernel/time/posix-timers.c 2015-08-17 05:52:51.000000000 +0200
  19864. +++ linux-4.1.6/kernel/time/posix-timers.c 2015-09-08 23:49:08.117866054 +0200
  19865. @@ -499,6 +499,7 @@
  19866. static struct pid *good_sigevent(sigevent_t * event)
  19867. {
  19868. struct task_struct *rtn = current->group_leader;
  19869. + int sig = event->sigev_signo;
  19870. if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
  19871. (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
  19872. @@ -507,7 +508,8 @@
  19873. return NULL;
  19874. if (((event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE) &&
  19875. - ((event->sigev_signo <= 0) || (event->sigev_signo > SIGRTMAX)))
  19876. + (sig <= 0 || sig > SIGRTMAX || sig_kernel_only(sig) ||
  19877. + sig_kernel_coredump(sig)))
  19878. return NULL;
  19879. return task_pid(rtn);
  19880. @@ -819,6 +821,20 @@
  19881. return overrun;
  19882. }
  19883. +/*
  19884. + * Protected by RCU!
  19885. + */
  19886. +static void timer_wait_for_callback(struct k_clock *kc, struct k_itimer *timr)
  19887. +{
  19888. +#ifdef CONFIG_PREEMPT_RT_FULL
  19889. + if (kc->timer_set == common_timer_set)
  19890. + hrtimer_wait_for_timer(&timr->it.real.timer);
  19891. + else
  19892. + /* FIXME: Whacky hack for posix-cpu-timers */
  19893. + schedule_timeout(1);
  19894. +#endif
  19895. +}
  19896. +
  19897. /* Set a POSIX.1b interval timer. */
  19898. /* timr->it_lock is taken. */
  19899. static int
  19900. @@ -896,6 +912,7 @@
  19901. if (!timr)
  19902. return -EINVAL;
  19903. + rcu_read_lock();
  19904. kc = clockid_to_kclock(timr->it_clock);
  19905. if (WARN_ON_ONCE(!kc || !kc->timer_set))
  19906. error = -EINVAL;
  19907. @@ -904,9 +921,12 @@
  19908. unlock_timer(timr, flag);
  19909. if (error == TIMER_RETRY) {
  19910. + timer_wait_for_callback(kc, timr);
  19911. rtn = NULL; // We already got the old time...
  19912. + rcu_read_unlock();
  19913. goto retry;
  19914. }
  19915. + rcu_read_unlock();
  19916. if (old_setting && !error &&
  19917. copy_to_user(old_setting, &old_spec, sizeof (old_spec)))
  19918. @@ -944,10 +964,15 @@
  19919. if (!timer)
  19920. return -EINVAL;
  19921. + rcu_read_lock();
  19922. if (timer_delete_hook(timer) == TIMER_RETRY) {
  19923. unlock_timer(timer, flags);
  19924. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  19925. + timer);
  19926. + rcu_read_unlock();
  19927. goto retry_delete;
  19928. }
  19929. + rcu_read_unlock();
  19930. spin_lock(&current->sighand->siglock);
  19931. list_del(&timer->list);
  19932. @@ -973,8 +998,18 @@
  19933. retry_delete:
  19934. spin_lock_irqsave(&timer->it_lock, flags);
  19935. + /* On RT we can race with a deletion */
  19936. + if (!timer->it_signal) {
  19937. + unlock_timer(timer, flags);
  19938. + return;
  19939. + }
  19940. +
  19941. if (timer_delete_hook(timer) == TIMER_RETRY) {
  19942. + rcu_read_lock();
  19943. unlock_timer(timer, flags);
  19944. + timer_wait_for_callback(clockid_to_kclock(timer->it_clock),
  19945. + timer);
  19946. + rcu_read_unlock();
  19947. goto retry_delete;
  19948. }
  19949. list_del(&timer->list);
  19950. diff -Nur linux-4.1.6.orig/kernel/time/tick-common.c linux-4.1.6/kernel/time/tick-common.c
  19951. --- linux-4.1.6.orig/kernel/time/tick-common.c 2015-08-17 05:52:51.000000000 +0200
  19952. +++ linux-4.1.6/kernel/time/tick-common.c 2015-09-08 23:49:08.117866054 +0200
  19953. @@ -78,13 +78,15 @@
  19954. static void tick_periodic(int cpu)
  19955. {
  19956. if (tick_do_timer_cpu == cpu) {
  19957. - write_seqlock(&jiffies_lock);
  19958. + raw_spin_lock(&jiffies_lock);
  19959. + write_seqcount_begin(&jiffies_seq);
  19960. /* Keep track of the next tick event */
  19961. tick_next_period = ktime_add(tick_next_period, tick_period);
  19962. do_timer(1);
  19963. - write_sequnlock(&jiffies_lock);
  19964. + write_seqcount_end(&jiffies_seq);
  19965. + raw_spin_unlock(&jiffies_lock);
  19966. update_wall_time();
  19967. }
  19968. @@ -146,9 +148,9 @@
  19969. ktime_t next;
  19970. do {
  19971. - seq = read_seqbegin(&jiffies_lock);
  19972. + seq = read_seqcount_begin(&jiffies_seq);
  19973. next = tick_next_period;
  19974. - } while (read_seqretry(&jiffies_lock, seq));
  19975. + } while (read_seqcount_retry(&jiffies_seq, seq));
  19976. clockevents_set_state(dev, CLOCK_EVT_STATE_ONESHOT);
  19977. diff -Nur linux-4.1.6.orig/kernel/time/tick-sched.c linux-4.1.6/kernel/time/tick-sched.c
  19978. --- linux-4.1.6.orig/kernel/time/tick-sched.c 2015-08-17 05:52:51.000000000 +0200
  19979. +++ linux-4.1.6/kernel/time/tick-sched.c 2015-09-08 23:49:08.117866054 +0200
  19980. @@ -62,7 +62,8 @@
  19981. return;
  19982. /* Reevalute with jiffies_lock held */
  19983. - write_seqlock(&jiffies_lock);
  19984. + raw_spin_lock(&jiffies_lock);
  19985. + write_seqcount_begin(&jiffies_seq);
  19986. delta = ktime_sub(now, last_jiffies_update);
  19987. if (delta.tv64 >= tick_period.tv64) {
  19988. @@ -85,10 +86,12 @@
  19989. /* Keep the tick_next_period variable up to date */
  19990. tick_next_period = ktime_add(last_jiffies_update, tick_period);
  19991. } else {
  19992. - write_sequnlock(&jiffies_lock);
  19993. + write_seqcount_end(&jiffies_seq);
  19994. + raw_spin_unlock(&jiffies_lock);
  19995. return;
  19996. }
  19997. - write_sequnlock(&jiffies_lock);
  19998. + write_seqcount_end(&jiffies_seq);
  19999. + raw_spin_unlock(&jiffies_lock);
  20000. update_wall_time();
  20001. }
  20002. @@ -99,12 +102,14 @@
  20003. {
  20004. ktime_t period;
  20005. - write_seqlock(&jiffies_lock);
  20006. + raw_spin_lock(&jiffies_lock);
  20007. + write_seqcount_begin(&jiffies_seq);
  20008. /* Did we start the jiffies update yet ? */
  20009. if (last_jiffies_update.tv64 == 0)
  20010. last_jiffies_update = tick_next_period;
  20011. period = last_jiffies_update;
  20012. - write_sequnlock(&jiffies_lock);
  20013. + write_seqcount_end(&jiffies_seq);
  20014. + raw_spin_unlock(&jiffies_lock);
  20015. return period;
  20016. }
  20017. @@ -176,6 +181,11 @@
  20018. return false;
  20019. }
  20020. + if (!arch_irq_work_has_interrupt()) {
  20021. + trace_tick_stop(0, "missing irq work interrupt\n");
  20022. + return false;
  20023. + }
  20024. +
  20025. /* sched_clock_tick() needs us? */
  20026. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  20027. /*
  20028. @@ -222,6 +232,7 @@
  20029. static DEFINE_PER_CPU(struct irq_work, nohz_full_kick_work) = {
  20030. .func = nohz_full_kick_work_func,
  20031. + .flags = IRQ_WORK_HARD_IRQ,
  20032. };
  20033. /*
  20034. @@ -578,10 +589,10 @@
  20035. /* Read jiffies and the time when jiffies were updated last */
  20036. do {
  20037. - seq = read_seqbegin(&jiffies_lock);
  20038. + seq = read_seqcount_begin(&jiffies_seq);
  20039. last_update = last_jiffies_update;
  20040. last_jiffies = jiffies;
  20041. - } while (read_seqretry(&jiffies_lock, seq));
  20042. + } while (read_seqcount_retry(&jiffies_seq, seq));
  20043. if (rcu_needs_cpu(&rcu_delta_jiffies) ||
  20044. arch_needs_cpu() || irq_work_needs_cpu()) {
  20045. @@ -759,14 +770,7 @@
  20046. return false;
  20047. if (unlikely(local_softirq_pending() && cpu_online(cpu))) {
  20048. - static int ratelimit;
  20049. -
  20050. - if (ratelimit < 10 &&
  20051. - (local_softirq_pending() & SOFTIRQ_STOP_IDLE_MASK)) {
  20052. - pr_warn("NOHZ: local_softirq_pending %02x\n",
  20053. - (unsigned int) local_softirq_pending());
  20054. - ratelimit++;
  20055. - }
  20056. + softirq_check_pending_idle();
  20057. return false;
  20058. }
  20059. @@ -1154,6 +1158,7 @@
  20060. * Emulate tick processing via per-CPU hrtimers:
  20061. */
  20062. hrtimer_init(&ts->sched_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
  20063. + ts->sched_timer.irqsafe = 1;
  20064. ts->sched_timer.function = tick_sched_timer;
  20065. /* Get the next period (per cpu) */
  20066. diff -Nur linux-4.1.6.orig/kernel/time/timekeeping.c linux-4.1.6/kernel/time/timekeeping.c
  20067. --- linux-4.1.6.orig/kernel/time/timekeeping.c 2015-08-17 05:52:51.000000000 +0200
  20068. +++ linux-4.1.6/kernel/time/timekeeping.c 2015-09-08 23:49:08.125865168 +0200
  20069. @@ -2065,8 +2065,10 @@
  20070. */
  20071. void xtime_update(unsigned long ticks)
  20072. {
  20073. - write_seqlock(&jiffies_lock);
  20074. + raw_spin_lock(&jiffies_lock);
  20075. + write_seqcount_begin(&jiffies_seq);
  20076. do_timer(ticks);
  20077. - write_sequnlock(&jiffies_lock);
  20078. + write_seqcount_end(&jiffies_seq);
  20079. + raw_spin_unlock(&jiffies_lock);
  20080. update_wall_time();
  20081. }
  20082. diff -Nur linux-4.1.6.orig/kernel/time/timekeeping.h linux-4.1.6/kernel/time/timekeeping.h
  20083. --- linux-4.1.6.orig/kernel/time/timekeeping.h 2015-08-17 05:52:51.000000000 +0200
  20084. +++ linux-4.1.6/kernel/time/timekeeping.h 2015-09-08 23:49:08.125865168 +0200
  20085. @@ -22,7 +22,8 @@
  20086. extern void do_timer(unsigned long ticks);
  20087. extern void update_wall_time(void);
  20088. -extern seqlock_t jiffies_lock;
  20089. +extern raw_spinlock_t jiffies_lock;
  20090. +extern seqcount_t jiffies_seq;
  20091. #define CS_NAME_LEN 32
  20092. diff -Nur linux-4.1.6.orig/kernel/time/timer.c linux-4.1.6/kernel/time/timer.c
  20093. --- linux-4.1.6.orig/kernel/time/timer.c 2015-08-17 05:52:51.000000000 +0200
  20094. +++ linux-4.1.6/kernel/time/timer.c 2015-09-08 23:49:08.125865168 +0200
  20095. @@ -78,6 +78,9 @@
  20096. struct tvec_base {
  20097. spinlock_t lock;
  20098. struct timer_list *running_timer;
  20099. +#ifdef CONFIG_PREEMPT_RT_FULL
  20100. + wait_queue_head_t wait_for_running_timer;
  20101. +#endif
  20102. unsigned long timer_jiffies;
  20103. unsigned long next_timer;
  20104. unsigned long active_timers;
  20105. @@ -768,6 +771,36 @@
  20106. }
  20107. }
  20108. +#ifndef CONFIG_PREEMPT_RT_FULL
  20109. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  20110. + struct tvec_base *old,
  20111. + struct tvec_base *new)
  20112. +{
  20113. + /* See the comment in lock_timer_base() */
  20114. + timer_set_base(timer, NULL);
  20115. + spin_unlock(&old->lock);
  20116. + spin_lock(&new->lock);
  20117. + timer_set_base(timer, new);
  20118. + return new;
  20119. +}
  20120. +#else
  20121. +static inline struct tvec_base *switch_timer_base(struct timer_list *timer,
  20122. + struct tvec_base *old,
  20123. + struct tvec_base *new)
  20124. +{
  20125. + /*
  20126. + * We cannot do the above because we might be preempted and
  20127. + * then the preempter would see NULL and loop forever.
  20128. + */
  20129. + if (spin_trylock(&new->lock)) {
  20130. + timer_set_base(timer, new);
  20131. + spin_unlock(&old->lock);
  20132. + return new;
  20133. + }
  20134. + return old;
  20135. +}
  20136. +#endif
  20137. +
  20138. static inline int
  20139. __mod_timer(struct timer_list *timer, unsigned long expires,
  20140. bool pending_only, int pinned)
  20141. @@ -798,14 +831,8 @@
  20142. * handler yet has not finished. This also guarantees that
  20143. * the timer is serialized wrt itself.
  20144. */
  20145. - if (likely(base->running_timer != timer)) {
  20146. - /* See the comment in lock_timer_base() */
  20147. - timer_set_base(timer, NULL);
  20148. - spin_unlock(&base->lock);
  20149. - base = new_base;
  20150. - spin_lock(&base->lock);
  20151. - timer_set_base(timer, base);
  20152. - }
  20153. + if (likely(base->running_timer != timer))
  20154. + base = switch_timer_base(timer, base, new_base);
  20155. }
  20156. timer->expires = expires;
  20157. @@ -979,6 +1006,29 @@
  20158. }
  20159. EXPORT_SYMBOL_GPL(add_timer_on);
  20160. +#ifdef CONFIG_PREEMPT_RT_FULL
  20161. +/*
  20162. + * Wait for a running timer
  20163. + */
  20164. +static void wait_for_running_timer(struct timer_list *timer)
  20165. +{
  20166. + struct tvec_base *base = timer->base;
  20167. +
  20168. + if (base->running_timer == timer)
  20169. + wait_event(base->wait_for_running_timer,
  20170. + base->running_timer != timer);
  20171. +}
  20172. +
  20173. +# define wakeup_timer_waiters(b) wake_up(&(b)->wait_for_running_timer)
  20174. +#else
  20175. +static inline void wait_for_running_timer(struct timer_list *timer)
  20176. +{
  20177. + cpu_relax();
  20178. +}
  20179. +
  20180. +# define wakeup_timer_waiters(b) do { } while (0)
  20181. +#endif
  20182. +
  20183. /**
  20184. * del_timer - deactive a timer.
  20185. * @timer: the timer to be deactivated
  20186. @@ -1036,7 +1086,7 @@
  20187. }
  20188. EXPORT_SYMBOL(try_to_del_timer_sync);
  20189. -#ifdef CONFIG_SMP
  20190. +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT_FULL)
  20191. static DEFINE_PER_CPU(struct tvec_base, __tvec_bases);
  20192. /**
  20193. @@ -1098,7 +1148,7 @@
  20194. int ret = try_to_del_timer_sync(timer);
  20195. if (ret >= 0)
  20196. return ret;
  20197. - cpu_relax();
  20198. + wait_for_running_timer(timer);
  20199. }
  20200. }
  20201. EXPORT_SYMBOL(del_timer_sync);
  20202. @@ -1219,15 +1269,17 @@
  20203. if (irqsafe) {
  20204. spin_unlock(&base->lock);
  20205. call_timer_fn(timer, fn, data);
  20206. + base->running_timer = NULL;
  20207. spin_lock(&base->lock);
  20208. } else {
  20209. spin_unlock_irq(&base->lock);
  20210. call_timer_fn(timer, fn, data);
  20211. + base->running_timer = NULL;
  20212. spin_lock_irq(&base->lock);
  20213. }
  20214. }
  20215. }
  20216. - base->running_timer = NULL;
  20217. + wakeup_timer_waiters(base);
  20218. spin_unlock_irq(&base->lock);
  20219. }
  20220. @@ -1367,6 +1419,14 @@
  20221. if (cpu_is_offline(smp_processor_id()))
  20222. return expires;
  20223. +#ifdef CONFIG_PREEMPT_RT_FULL
  20224. + /*
  20225. + * On PREEMPT_RT we cannot sleep here. As a result we can't take
  20226. + * the base lock to check when the next timer is pending and so
  20227. + * we assume the next jiffy.
  20228. + */
  20229. + return now + 1;
  20230. +#endif
  20231. spin_lock(&base->lock);
  20232. if (base->active_timers) {
  20233. if (time_before_eq(base->next_timer, base->timer_jiffies))
  20234. @@ -1392,13 +1452,13 @@
  20235. /* Note: this timer irq context must be accounted for as well. */
  20236. account_process_tick(p, user_tick);
  20237. + scheduler_tick();
  20238. run_local_timers();
  20239. rcu_check_callbacks(user_tick);
  20240. -#ifdef CONFIG_IRQ_WORK
  20241. +#if defined(CONFIG_IRQ_WORK) && !defined(CONFIG_PREEMPT_RT_FULL)
  20242. if (in_irq())
  20243. irq_work_tick();
  20244. #endif
  20245. - scheduler_tick();
  20246. run_posix_cpu_timers(p);
  20247. }
  20248. @@ -1411,6 +1471,10 @@
  20249. hrtimer_run_pending();
  20250. +#if defined(CONFIG_IRQ_WORK) && defined(CONFIG_PREEMPT_RT_FULL)
  20251. + irq_work_tick();
  20252. +#endif
  20253. +
  20254. if (time_after_eq(jiffies, base->timer_jiffies))
  20255. __run_timers(base);
  20256. }
  20257. @@ -1566,7 +1630,7 @@
  20258. BUG_ON(cpu_online(cpu));
  20259. old_base = per_cpu(tvec_bases, cpu);
  20260. - new_base = get_cpu_var(tvec_bases);
  20261. + new_base = get_local_var(tvec_bases);
  20262. /*
  20263. * The caller is globally serialized and nobody else
  20264. * takes two locks at once, deadlock is not possible.
  20265. @@ -1590,7 +1654,7 @@
  20266. spin_unlock(&old_base->lock);
  20267. spin_unlock_irq(&new_base->lock);
  20268. - put_cpu_var(tvec_bases);
  20269. + put_local_var(tvec_bases);
  20270. }
  20271. static int timer_cpu_notify(struct notifier_block *self,
  20272. @@ -1625,6 +1689,9 @@
  20273. base->cpu = cpu;
  20274. per_cpu(tvec_bases, cpu) = base;
  20275. spin_lock_init(&base->lock);
  20276. +#ifdef CONFIG_PREEMPT_RT_FULL
  20277. + init_waitqueue_head(&base->wait_for_running_timer);
  20278. +#endif
  20279. for (j = 0; j < TVN_SIZE; j++) {
  20280. INIT_LIST_HEAD(base->tv5.vec + j);
  20281. diff -Nur linux-4.1.6.orig/kernel/trace/Kconfig linux-4.1.6/kernel/trace/Kconfig
  20282. --- linux-4.1.6.orig/kernel/trace/Kconfig 2015-08-17 05:52:51.000000000 +0200
  20283. +++ linux-4.1.6/kernel/trace/Kconfig 2015-09-08 23:49:08.125865168 +0200
  20284. @@ -187,6 +187,24 @@
  20285. enabled. This option and the preempt-off timing option can be
  20286. used together or separately.)
  20287. +config INTERRUPT_OFF_HIST
  20288. + bool "Interrupts-off Latency Histogram"
  20289. + depends on IRQSOFF_TRACER
  20290. + help
  20291. + This option generates continuously updated histograms (one per cpu)
  20292. + of the duration of time periods with interrupts disabled. The
  20293. + histograms are disabled by default. To enable them, write a non-zero
  20294. + number to
  20295. +
  20296. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  20297. +
  20298. + If PREEMPT_OFF_HIST is also selected, additional histograms (one
  20299. + per cpu) are generated that accumulate the duration of time periods
  20300. + when both interrupts and preemption are disabled. The histogram data
  20301. + will be located in the debug file system at
  20302. +
  20303. + /sys/kernel/debug/tracing/latency_hist/irqsoff
  20304. +
  20305. config PREEMPT_TRACER
  20306. bool "Preemption-off Latency Tracer"
  20307. default n
  20308. @@ -211,6 +229,24 @@
  20309. enabled. This option and the irqs-off timing option can be
  20310. used together or separately.)
  20311. +config PREEMPT_OFF_HIST
  20312. + bool "Preemption-off Latency Histogram"
  20313. + depends on PREEMPT_TRACER
  20314. + help
  20315. + This option generates continuously updated histograms (one per cpu)
  20316. + of the duration of time periods with preemption disabled. The
  20317. + histograms are disabled by default. To enable them, write a non-zero
  20318. + number to
  20319. +
  20320. + /sys/kernel/debug/tracing/latency_hist/enable/preemptirqsoff
  20321. +
  20322. + If INTERRUPT_OFF_HIST is also selected, additional histograms (one
  20323. + per cpu) are generated that accumulate the duration of time periods
  20324. + when both interrupts and preemption are disabled. The histogram data
  20325. + will be located in the debug file system at
  20326. +
  20327. + /sys/kernel/debug/tracing/latency_hist/preemptoff
  20328. +
  20329. config SCHED_TRACER
  20330. bool "Scheduling Latency Tracer"
  20331. select GENERIC_TRACER
  20332. @@ -221,6 +257,74 @@
  20333. This tracer tracks the latency of the highest priority task
  20334. to be scheduled in, starting from the point it has woken up.
  20335. +config WAKEUP_LATENCY_HIST
  20336. + bool "Scheduling Latency Histogram"
  20337. + depends on SCHED_TRACER
  20338. + help
  20339. + This option generates continuously updated histograms (one per cpu)
  20340. + of the scheduling latency of the highest priority task.
  20341. + The histograms are disabled by default. To enable them, write a
  20342. + non-zero number to
  20343. +
  20344. + /sys/kernel/debug/tracing/latency_hist/enable/wakeup
  20345. +
  20346. + Two different algorithms are used, one to determine the latency of
  20347. + processes that exclusively use the highest priority of the system and
  20348. + another one to determine the latency of processes that share the
  20349. + highest system priority with other processes. The former is used to
  20350. + improve hardware and system software, the latter to optimize the
  20351. + priority design of a given system. The histogram data will be
  20352. + located in the debug file system at
  20353. +
  20354. + /sys/kernel/debug/tracing/latency_hist/wakeup
  20355. +
  20356. + and
  20357. +
  20358. + /sys/kernel/debug/tracing/latency_hist/wakeup/sharedprio
  20359. +
  20360. + If both Scheduling Latency Histogram and Missed Timer Offsets
  20361. + Histogram are selected, additional histogram data will be collected
  20362. + that contain, in addition to the wakeup latency, the timer latency, in
  20363. + case the wakeup was triggered by an expired timer. These histograms
  20364. + are available in the
  20365. +
  20366. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  20367. +
  20368. + directory. They reflect the apparent interrupt and scheduling latency
  20369. + and are best suitable to determine the worst-case latency of a given
  20370. + system. To enable these histograms, write a non-zero number to
  20371. +
  20372. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  20373. +
  20374. +config MISSED_TIMER_OFFSETS_HIST
  20375. + depends on HIGH_RES_TIMERS
  20376. + select GENERIC_TRACER
  20377. + bool "Missed Timer Offsets Histogram"
  20378. + help
  20379. + Generate a histogram of missed timer offsets in microseconds. The
  20380. + histograms are disabled by default. To enable them, write a non-zero
  20381. + number to
  20382. +
  20383. + /sys/kernel/debug/tracing/latency_hist/enable/missed_timer_offsets
  20384. +
  20385. + The histogram data will be located in the debug file system at
  20386. +
  20387. + /sys/kernel/debug/tracing/latency_hist/missed_timer_offsets
  20388. +
  20389. + If both Scheduling Latency Histogram and Missed Timer Offsets
  20390. + Histogram are selected, additional histogram data will be collected
  20391. + that contain, in addition to the wakeup latency, the timer latency, in
  20392. + case the wakeup was triggered by an expired timer. These histograms
  20393. + are available in the
  20394. +
  20395. + /sys/kernel/debug/tracing/latency_hist/timerandwakeup
  20396. +
  20397. + directory. They reflect the apparent interrupt and scheduling latency
  20398. + and are best suitable to determine the worst-case latency of a given
  20399. + system. To enable these histograms, write a non-zero number to
  20400. +
  20401. + /sys/kernel/debug/tracing/latency_hist/enable/timerandwakeup
  20402. +
  20403. config ENABLE_DEFAULT_TRACERS
  20404. bool "Trace process context switches and events"
  20405. depends on !GENERIC_TRACER
  20406. diff -Nur linux-4.1.6.orig/kernel/trace/latency_hist.c linux-4.1.6/kernel/trace/latency_hist.c
  20407. --- linux-4.1.6.orig/kernel/trace/latency_hist.c 1970-01-01 01:00:00.000000000 +0100
  20408. +++ linux-4.1.6/kernel/trace/latency_hist.c 2015-09-08 23:49:08.125865168 +0200
  20409. @@ -0,0 +1,1178 @@
  20410. +/*
  20411. + * kernel/trace/latency_hist.c
  20412. + *
  20413. + * Add support for histograms of preemption-off latency and
  20414. + * interrupt-off latency and wakeup latency, it depends on
  20415. + * Real-Time Preemption Support.
  20416. + *
  20417. + * Copyright (C) 2005 MontaVista Software, Inc.
  20418. + * Yi Yang <yyang@ch.mvista.com>
  20419. + *
  20420. + * Converted to work with the new latency tracer.
  20421. + * Copyright (C) 2008 Red Hat, Inc.
  20422. + * Steven Rostedt <srostedt@redhat.com>
  20423. + *
  20424. + */
  20425. +#include <linux/module.h>
  20426. +#include <linux/debugfs.h>
  20427. +#include <linux/seq_file.h>
  20428. +#include <linux/percpu.h>
  20429. +#include <linux/kallsyms.h>
  20430. +#include <linux/uaccess.h>
  20431. +#include <linux/sched.h>
  20432. +#include <linux/sched/rt.h>
  20433. +#include <linux/slab.h>
  20434. +#include <linux/atomic.h>
  20435. +#include <asm/div64.h>
  20436. +
  20437. +#include "trace.h"
  20438. +#include <trace/events/sched.h>
  20439. +
  20440. +#define NSECS_PER_USECS 1000L
  20441. +
  20442. +#define CREATE_TRACE_POINTS
  20443. +#include <trace/events/hist.h>
  20444. +
  20445. +enum {
  20446. + IRQSOFF_LATENCY = 0,
  20447. + PREEMPTOFF_LATENCY,
  20448. + PREEMPTIRQSOFF_LATENCY,
  20449. + WAKEUP_LATENCY,
  20450. + WAKEUP_LATENCY_SHAREDPRIO,
  20451. + MISSED_TIMER_OFFSETS,
  20452. + TIMERANDWAKEUP_LATENCY,
  20453. + MAX_LATENCY_TYPE,
  20454. +};
  20455. +
  20456. +#define MAX_ENTRY_NUM 10240
  20457. +
  20458. +struct hist_data {
  20459. + atomic_t hist_mode; /* 0 log, 1 don't log */
  20460. + long offset; /* set it to MAX_ENTRY_NUM/2 for a bipolar scale */
  20461. + long min_lat;
  20462. + long max_lat;
  20463. + unsigned long long below_hist_bound_samples;
  20464. + unsigned long long above_hist_bound_samples;
  20465. + long long accumulate_lat;
  20466. + unsigned long long total_samples;
  20467. + unsigned long long hist_array[MAX_ENTRY_NUM];
  20468. +};
  20469. +
  20470. +struct enable_data {
  20471. + int latency_type;
  20472. + int enabled;
  20473. +};
  20474. +
  20475. +static char *latency_hist_dir_root = "latency_hist";
  20476. +
  20477. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  20478. +static DEFINE_PER_CPU(struct hist_data, irqsoff_hist);
  20479. +static char *irqsoff_hist_dir = "irqsoff";
  20480. +static DEFINE_PER_CPU(cycles_t, hist_irqsoff_start);
  20481. +static DEFINE_PER_CPU(int, hist_irqsoff_counting);
  20482. +#endif
  20483. +
  20484. +#ifdef CONFIG_PREEMPT_OFF_HIST
  20485. +static DEFINE_PER_CPU(struct hist_data, preemptoff_hist);
  20486. +static char *preemptoff_hist_dir = "preemptoff";
  20487. +static DEFINE_PER_CPU(cycles_t, hist_preemptoff_start);
  20488. +static DEFINE_PER_CPU(int, hist_preemptoff_counting);
  20489. +#endif
  20490. +
  20491. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  20492. +static DEFINE_PER_CPU(struct hist_data, preemptirqsoff_hist);
  20493. +static char *preemptirqsoff_hist_dir = "preemptirqsoff";
  20494. +static DEFINE_PER_CPU(cycles_t, hist_preemptirqsoff_start);
  20495. +static DEFINE_PER_CPU(int, hist_preemptirqsoff_counting);
  20496. +#endif
  20497. +
  20498. +#if defined(CONFIG_PREEMPT_OFF_HIST) || defined(CONFIG_INTERRUPT_OFF_HIST)
  20499. +static notrace void probe_preemptirqsoff_hist(void *v, int reason, int start);
  20500. +static struct enable_data preemptirqsoff_enabled_data = {
  20501. + .latency_type = PREEMPTIRQSOFF_LATENCY,
  20502. + .enabled = 0,
  20503. +};
  20504. +#endif
  20505. +
  20506. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20507. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20508. +struct maxlatproc_data {
  20509. + char comm[FIELD_SIZEOF(struct task_struct, comm)];
  20510. + char current_comm[FIELD_SIZEOF(struct task_struct, comm)];
  20511. + int pid;
  20512. + int current_pid;
  20513. + int prio;
  20514. + int current_prio;
  20515. + long latency;
  20516. + long timeroffset;
  20517. + cycle_t timestamp;
  20518. +};
  20519. +#endif
  20520. +
  20521. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  20522. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist);
  20523. +static DEFINE_PER_CPU(struct hist_data, wakeup_latency_hist_sharedprio);
  20524. +static char *wakeup_latency_hist_dir = "wakeup";
  20525. +static char *wakeup_latency_hist_dir_sharedprio = "sharedprio";
  20526. +static notrace void probe_wakeup_latency_hist_start(void *v,
  20527. + struct task_struct *p, int success);
  20528. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  20529. + struct task_struct *prev, struct task_struct *next);
  20530. +static notrace void probe_sched_migrate_task(void *,
  20531. + struct task_struct *task, int cpu);
  20532. +static struct enable_data wakeup_latency_enabled_data = {
  20533. + .latency_type = WAKEUP_LATENCY,
  20534. + .enabled = 0,
  20535. +};
  20536. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc);
  20537. +static DEFINE_PER_CPU(struct maxlatproc_data, wakeup_maxlatproc_sharedprio);
  20538. +static DEFINE_PER_CPU(struct task_struct *, wakeup_task);
  20539. +static DEFINE_PER_CPU(int, wakeup_sharedprio);
  20540. +static unsigned long wakeup_pid;
  20541. +#endif
  20542. +
  20543. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  20544. +static DEFINE_PER_CPU(struct hist_data, missed_timer_offsets);
  20545. +static char *missed_timer_offsets_dir = "missed_timer_offsets";
  20546. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  20547. + long long offset, struct task_struct *curr, struct task_struct *task);
  20548. +static struct enable_data missed_timer_offsets_enabled_data = {
  20549. + .latency_type = MISSED_TIMER_OFFSETS,
  20550. + .enabled = 0,
  20551. +};
  20552. +static DEFINE_PER_CPU(struct maxlatproc_data, missed_timer_offsets_maxlatproc);
  20553. +static unsigned long missed_timer_offsets_pid;
  20554. +#endif
  20555. +
  20556. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  20557. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20558. +static DEFINE_PER_CPU(struct hist_data, timerandwakeup_latency_hist);
  20559. +static char *timerandwakeup_latency_hist_dir = "timerandwakeup";
  20560. +static struct enable_data timerandwakeup_enabled_data = {
  20561. + .latency_type = TIMERANDWAKEUP_LATENCY,
  20562. + .enabled = 0,
  20563. +};
  20564. +static DEFINE_PER_CPU(struct maxlatproc_data, timerandwakeup_maxlatproc);
  20565. +#endif
  20566. +
  20567. +void notrace latency_hist(int latency_type, int cpu, long latency,
  20568. + long timeroffset, cycle_t stop,
  20569. + struct task_struct *p)
  20570. +{
  20571. + struct hist_data *my_hist;
  20572. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20573. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20574. + struct maxlatproc_data *mp = NULL;
  20575. +#endif
  20576. +
  20577. + if (!cpu_possible(cpu) || latency_type < 0 ||
  20578. + latency_type >= MAX_LATENCY_TYPE)
  20579. + return;
  20580. +
  20581. + switch (latency_type) {
  20582. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  20583. + case IRQSOFF_LATENCY:
  20584. + my_hist = &per_cpu(irqsoff_hist, cpu);
  20585. + break;
  20586. +#endif
  20587. +#ifdef CONFIG_PREEMPT_OFF_HIST
  20588. + case PREEMPTOFF_LATENCY:
  20589. + my_hist = &per_cpu(preemptoff_hist, cpu);
  20590. + break;
  20591. +#endif
  20592. +#if defined(CONFIG_PREEMPT_OFF_HIST) && defined(CONFIG_INTERRUPT_OFF_HIST)
  20593. + case PREEMPTIRQSOFF_LATENCY:
  20594. + my_hist = &per_cpu(preemptirqsoff_hist, cpu);
  20595. + break;
  20596. +#endif
  20597. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  20598. + case WAKEUP_LATENCY:
  20599. + my_hist = &per_cpu(wakeup_latency_hist, cpu);
  20600. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  20601. + break;
  20602. + case WAKEUP_LATENCY_SHAREDPRIO:
  20603. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  20604. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  20605. + break;
  20606. +#endif
  20607. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  20608. + case MISSED_TIMER_OFFSETS:
  20609. + my_hist = &per_cpu(missed_timer_offsets, cpu);
  20610. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  20611. + break;
  20612. +#endif
  20613. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  20614. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20615. + case TIMERANDWAKEUP_LATENCY:
  20616. + my_hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  20617. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  20618. + break;
  20619. +#endif
  20620. +
  20621. + default:
  20622. + return;
  20623. + }
  20624. +
  20625. + latency += my_hist->offset;
  20626. +
  20627. + if (atomic_read(&my_hist->hist_mode) == 0)
  20628. + return;
  20629. +
  20630. + if (latency < 0 || latency >= MAX_ENTRY_NUM) {
  20631. + if (latency < 0)
  20632. + my_hist->below_hist_bound_samples++;
  20633. + else
  20634. + my_hist->above_hist_bound_samples++;
  20635. + } else
  20636. + my_hist->hist_array[latency]++;
  20637. +
  20638. + if (unlikely(latency > my_hist->max_lat ||
  20639. + my_hist->min_lat == LONG_MAX)) {
  20640. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20641. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20642. + if (latency_type == WAKEUP_LATENCY ||
  20643. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  20644. + latency_type == MISSED_TIMER_OFFSETS ||
  20645. + latency_type == TIMERANDWAKEUP_LATENCY) {
  20646. + strncpy(mp->comm, p->comm, sizeof(mp->comm));
  20647. + strncpy(mp->current_comm, current->comm,
  20648. + sizeof(mp->current_comm));
  20649. + mp->pid = task_pid_nr(p);
  20650. + mp->current_pid = task_pid_nr(current);
  20651. + mp->prio = p->prio;
  20652. + mp->current_prio = current->prio;
  20653. + mp->latency = latency;
  20654. + mp->timeroffset = timeroffset;
  20655. + mp->timestamp = stop;
  20656. + }
  20657. +#endif
  20658. + my_hist->max_lat = latency;
  20659. + }
  20660. + if (unlikely(latency < my_hist->min_lat))
  20661. + my_hist->min_lat = latency;
  20662. + my_hist->total_samples++;
  20663. + my_hist->accumulate_lat += latency;
  20664. +}
  20665. +
  20666. +static void *l_start(struct seq_file *m, loff_t *pos)
  20667. +{
  20668. + loff_t *index_ptr = NULL;
  20669. + loff_t index = *pos;
  20670. + struct hist_data *my_hist = m->private;
  20671. +
  20672. + if (index == 0) {
  20673. + char minstr[32], avgstr[32], maxstr[32];
  20674. +
  20675. + atomic_dec(&my_hist->hist_mode);
  20676. +
  20677. + if (likely(my_hist->total_samples)) {
  20678. + long avg = (long) div64_s64(my_hist->accumulate_lat,
  20679. + my_hist->total_samples);
  20680. + snprintf(minstr, sizeof(minstr), "%ld",
  20681. + my_hist->min_lat - my_hist->offset);
  20682. + snprintf(avgstr, sizeof(avgstr), "%ld",
  20683. + avg - my_hist->offset);
  20684. + snprintf(maxstr, sizeof(maxstr), "%ld",
  20685. + my_hist->max_lat - my_hist->offset);
  20686. + } else {
  20687. + strcpy(minstr, "<undef>");
  20688. + strcpy(avgstr, minstr);
  20689. + strcpy(maxstr, minstr);
  20690. + }
  20691. +
  20692. + seq_printf(m, "#Minimum latency: %s microseconds\n"
  20693. + "#Average latency: %s microseconds\n"
  20694. + "#Maximum latency: %s microseconds\n"
  20695. + "#Total samples: %llu\n"
  20696. + "#There are %llu samples lower than %ld"
  20697. + " microseconds.\n"
  20698. + "#There are %llu samples greater or equal"
  20699. + " than %ld microseconds.\n"
  20700. + "#usecs\t%16s\n",
  20701. + minstr, avgstr, maxstr,
  20702. + my_hist->total_samples,
  20703. + my_hist->below_hist_bound_samples,
  20704. + -my_hist->offset,
  20705. + my_hist->above_hist_bound_samples,
  20706. + MAX_ENTRY_NUM - my_hist->offset,
  20707. + "samples");
  20708. + }
  20709. + if (index < MAX_ENTRY_NUM) {
  20710. + index_ptr = kmalloc(sizeof(loff_t), GFP_KERNEL);
  20711. + if (index_ptr)
  20712. + *index_ptr = index;
  20713. + }
  20714. +
  20715. + return index_ptr;
  20716. +}
  20717. +
  20718. +static void *l_next(struct seq_file *m, void *p, loff_t *pos)
  20719. +{
  20720. + loff_t *index_ptr = p;
  20721. + struct hist_data *my_hist = m->private;
  20722. +
  20723. + if (++*pos >= MAX_ENTRY_NUM) {
  20724. + atomic_inc(&my_hist->hist_mode);
  20725. + return NULL;
  20726. + }
  20727. + *index_ptr = *pos;
  20728. + return index_ptr;
  20729. +}
  20730. +
  20731. +static void l_stop(struct seq_file *m, void *p)
  20732. +{
  20733. + kfree(p);
  20734. +}
  20735. +
  20736. +static int l_show(struct seq_file *m, void *p)
  20737. +{
  20738. + int index = *(loff_t *) p;
  20739. + struct hist_data *my_hist = m->private;
  20740. +
  20741. + seq_printf(m, "%6ld\t%16llu\n", index - my_hist->offset,
  20742. + my_hist->hist_array[index]);
  20743. + return 0;
  20744. +}
  20745. +
  20746. +static const struct seq_operations latency_hist_seq_op = {
  20747. + .start = l_start,
  20748. + .next = l_next,
  20749. + .stop = l_stop,
  20750. + .show = l_show
  20751. +};
  20752. +
  20753. +static int latency_hist_open(struct inode *inode, struct file *file)
  20754. +{
  20755. + int ret;
  20756. +
  20757. + ret = seq_open(file, &latency_hist_seq_op);
  20758. + if (!ret) {
  20759. + struct seq_file *seq = file->private_data;
  20760. + seq->private = inode->i_private;
  20761. + }
  20762. + return ret;
  20763. +}
  20764. +
  20765. +static const struct file_operations latency_hist_fops = {
  20766. + .open = latency_hist_open,
  20767. + .read = seq_read,
  20768. + .llseek = seq_lseek,
  20769. + .release = seq_release,
  20770. +};
  20771. +
  20772. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20773. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20774. +static void clear_maxlatprocdata(struct maxlatproc_data *mp)
  20775. +{
  20776. + mp->comm[0] = mp->current_comm[0] = '\0';
  20777. + mp->prio = mp->current_prio = mp->pid = mp->current_pid =
  20778. + mp->latency = mp->timeroffset = -1;
  20779. + mp->timestamp = 0;
  20780. +}
  20781. +#endif
  20782. +
  20783. +static void hist_reset(struct hist_data *hist)
  20784. +{
  20785. + atomic_dec(&hist->hist_mode);
  20786. +
  20787. + memset(hist->hist_array, 0, sizeof(hist->hist_array));
  20788. + hist->below_hist_bound_samples = 0ULL;
  20789. + hist->above_hist_bound_samples = 0ULL;
  20790. + hist->min_lat = LONG_MAX;
  20791. + hist->max_lat = LONG_MIN;
  20792. + hist->total_samples = 0ULL;
  20793. + hist->accumulate_lat = 0LL;
  20794. +
  20795. + atomic_inc(&hist->hist_mode);
  20796. +}
  20797. +
  20798. +static ssize_t
  20799. +latency_hist_reset(struct file *file, const char __user *a,
  20800. + size_t size, loff_t *off)
  20801. +{
  20802. + int cpu;
  20803. + struct hist_data *hist = NULL;
  20804. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20805. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20806. + struct maxlatproc_data *mp = NULL;
  20807. +#endif
  20808. + off_t latency_type = (off_t) file->private_data;
  20809. +
  20810. + for_each_online_cpu(cpu) {
  20811. +
  20812. + switch (latency_type) {
  20813. +#ifdef CONFIG_PREEMPT_OFF_HIST
  20814. + case PREEMPTOFF_LATENCY:
  20815. + hist = &per_cpu(preemptoff_hist, cpu);
  20816. + break;
  20817. +#endif
  20818. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  20819. + case IRQSOFF_LATENCY:
  20820. + hist = &per_cpu(irqsoff_hist, cpu);
  20821. + break;
  20822. +#endif
  20823. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  20824. + case PREEMPTIRQSOFF_LATENCY:
  20825. + hist = &per_cpu(preemptirqsoff_hist, cpu);
  20826. + break;
  20827. +#endif
  20828. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  20829. + case WAKEUP_LATENCY:
  20830. + hist = &per_cpu(wakeup_latency_hist, cpu);
  20831. + mp = &per_cpu(wakeup_maxlatproc, cpu);
  20832. + break;
  20833. + case WAKEUP_LATENCY_SHAREDPRIO:
  20834. + hist = &per_cpu(wakeup_latency_hist_sharedprio, cpu);
  20835. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, cpu);
  20836. + break;
  20837. +#endif
  20838. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  20839. + case MISSED_TIMER_OFFSETS:
  20840. + hist = &per_cpu(missed_timer_offsets, cpu);
  20841. + mp = &per_cpu(missed_timer_offsets_maxlatproc, cpu);
  20842. + break;
  20843. +#endif
  20844. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  20845. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20846. + case TIMERANDWAKEUP_LATENCY:
  20847. + hist = &per_cpu(timerandwakeup_latency_hist, cpu);
  20848. + mp = &per_cpu(timerandwakeup_maxlatproc, cpu);
  20849. + break;
  20850. +#endif
  20851. + }
  20852. +
  20853. + hist_reset(hist);
  20854. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20855. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20856. + if (latency_type == WAKEUP_LATENCY ||
  20857. + latency_type == WAKEUP_LATENCY_SHAREDPRIO ||
  20858. + latency_type == MISSED_TIMER_OFFSETS ||
  20859. + latency_type == TIMERANDWAKEUP_LATENCY)
  20860. + clear_maxlatprocdata(mp);
  20861. +#endif
  20862. + }
  20863. +
  20864. + return size;
  20865. +}
  20866. +
  20867. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20868. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20869. +static ssize_t
  20870. +show_pid(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  20871. +{
  20872. + char buf[64];
  20873. + int r;
  20874. + unsigned long *this_pid = file->private_data;
  20875. +
  20876. + r = snprintf(buf, sizeof(buf), "%lu\n", *this_pid);
  20877. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  20878. +}
  20879. +
  20880. +static ssize_t do_pid(struct file *file, const char __user *ubuf,
  20881. + size_t cnt, loff_t *ppos)
  20882. +{
  20883. + char buf[64];
  20884. + unsigned long pid;
  20885. + unsigned long *this_pid = file->private_data;
  20886. +
  20887. + if (cnt >= sizeof(buf))
  20888. + return -EINVAL;
  20889. +
  20890. + if (copy_from_user(&buf, ubuf, cnt))
  20891. + return -EFAULT;
  20892. +
  20893. + buf[cnt] = '\0';
  20894. +
  20895. + if (kstrtoul(buf, 10, &pid))
  20896. + return -EINVAL;
  20897. +
  20898. + *this_pid = pid;
  20899. +
  20900. + return cnt;
  20901. +}
  20902. +#endif
  20903. +
  20904. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  20905. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  20906. +static ssize_t
  20907. +show_maxlatproc(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  20908. +{
  20909. + int r;
  20910. + struct maxlatproc_data *mp = file->private_data;
  20911. + int strmaxlen = (TASK_COMM_LEN * 2) + (8 * 8);
  20912. + unsigned long long t;
  20913. + unsigned long usecs, secs;
  20914. + char *buf;
  20915. +
  20916. + if (mp->pid == -1 || mp->current_pid == -1) {
  20917. + buf = "(none)\n";
  20918. + return simple_read_from_buffer(ubuf, cnt, ppos, buf,
  20919. + strlen(buf));
  20920. + }
  20921. +
  20922. + buf = kmalloc(strmaxlen, GFP_KERNEL);
  20923. + if (buf == NULL)
  20924. + return -ENOMEM;
  20925. +
  20926. + t = ns2usecs(mp->timestamp);
  20927. + usecs = do_div(t, USEC_PER_SEC);
  20928. + secs = (unsigned long) t;
  20929. + r = snprintf(buf, strmaxlen,
  20930. + "%d %d %ld (%ld) %s <- %d %d %s %lu.%06lu\n", mp->pid,
  20931. + MAX_RT_PRIO-1 - mp->prio, mp->latency, mp->timeroffset, mp->comm,
  20932. + mp->current_pid, MAX_RT_PRIO-1 - mp->current_prio, mp->current_comm,
  20933. + secs, usecs);
  20934. + r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  20935. + kfree(buf);
  20936. + return r;
  20937. +}
  20938. +#endif
  20939. +
  20940. +static ssize_t
  20941. +show_enable(struct file *file, char __user *ubuf, size_t cnt, loff_t *ppos)
  20942. +{
  20943. + char buf[64];
  20944. + struct enable_data *ed = file->private_data;
  20945. + int r;
  20946. +
  20947. + r = snprintf(buf, sizeof(buf), "%d\n", ed->enabled);
  20948. + return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
  20949. +}
  20950. +
  20951. +static ssize_t
  20952. +do_enable(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos)
  20953. +{
  20954. + char buf[64];
  20955. + long enable;
  20956. + struct enable_data *ed = file->private_data;
  20957. +
  20958. + if (cnt >= sizeof(buf))
  20959. + return -EINVAL;
  20960. +
  20961. + if (copy_from_user(&buf, ubuf, cnt))
  20962. + return -EFAULT;
  20963. +
  20964. + buf[cnt] = 0;
  20965. +
  20966. + if (kstrtoul(buf, 10, &enable))
  20967. + return -EINVAL;
  20968. +
  20969. + if ((enable && ed->enabled) || (!enable && !ed->enabled))
  20970. + return cnt;
  20971. +
  20972. + if (enable) {
  20973. + int ret;
  20974. +
  20975. + switch (ed->latency_type) {
  20976. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  20977. + case PREEMPTIRQSOFF_LATENCY:
  20978. + ret = register_trace_preemptirqsoff_hist(
  20979. + probe_preemptirqsoff_hist, NULL);
  20980. + if (ret) {
  20981. + pr_info("wakeup trace: Couldn't assign "
  20982. + "probe_preemptirqsoff_hist "
  20983. + "to trace_preemptirqsoff_hist\n");
  20984. + return ret;
  20985. + }
  20986. + break;
  20987. +#endif
  20988. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  20989. + case WAKEUP_LATENCY:
  20990. + ret = register_trace_sched_wakeup(
  20991. + probe_wakeup_latency_hist_start, NULL);
  20992. + if (ret) {
  20993. + pr_info("wakeup trace: Couldn't assign "
  20994. + "probe_wakeup_latency_hist_start "
  20995. + "to trace_sched_wakeup\n");
  20996. + return ret;
  20997. + }
  20998. + ret = register_trace_sched_wakeup_new(
  20999. + probe_wakeup_latency_hist_start, NULL);
  21000. + if (ret) {
  21001. + pr_info("wakeup trace: Couldn't assign "
  21002. + "probe_wakeup_latency_hist_start "
  21003. + "to trace_sched_wakeup_new\n");
  21004. + unregister_trace_sched_wakeup(
  21005. + probe_wakeup_latency_hist_start, NULL);
  21006. + return ret;
  21007. + }
  21008. + ret = register_trace_sched_switch(
  21009. + probe_wakeup_latency_hist_stop, NULL);
  21010. + if (ret) {
  21011. + pr_info("wakeup trace: Couldn't assign "
  21012. + "probe_wakeup_latency_hist_stop "
  21013. + "to trace_sched_switch\n");
  21014. + unregister_trace_sched_wakeup(
  21015. + probe_wakeup_latency_hist_start, NULL);
  21016. + unregister_trace_sched_wakeup_new(
  21017. + probe_wakeup_latency_hist_start, NULL);
  21018. + return ret;
  21019. + }
  21020. + ret = register_trace_sched_migrate_task(
  21021. + probe_sched_migrate_task, NULL);
  21022. + if (ret) {
  21023. + pr_info("wakeup trace: Couldn't assign "
  21024. + "probe_sched_migrate_task "
  21025. + "to trace_sched_migrate_task\n");
  21026. + unregister_trace_sched_wakeup(
  21027. + probe_wakeup_latency_hist_start, NULL);
  21028. + unregister_trace_sched_wakeup_new(
  21029. + probe_wakeup_latency_hist_start, NULL);
  21030. + unregister_trace_sched_switch(
  21031. + probe_wakeup_latency_hist_stop, NULL);
  21032. + return ret;
  21033. + }
  21034. + break;
  21035. +#endif
  21036. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21037. + case MISSED_TIMER_OFFSETS:
  21038. + ret = register_trace_hrtimer_interrupt(
  21039. + probe_hrtimer_interrupt, NULL);
  21040. + if (ret) {
  21041. + pr_info("wakeup trace: Couldn't assign "
  21042. + "probe_hrtimer_interrupt "
  21043. + "to trace_hrtimer_interrupt\n");
  21044. + return ret;
  21045. + }
  21046. + break;
  21047. +#endif
  21048. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  21049. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21050. + case TIMERANDWAKEUP_LATENCY:
  21051. + if (!wakeup_latency_enabled_data.enabled ||
  21052. + !missed_timer_offsets_enabled_data.enabled)
  21053. + return -EINVAL;
  21054. + break;
  21055. +#endif
  21056. + default:
  21057. + break;
  21058. + }
  21059. + } else {
  21060. + switch (ed->latency_type) {
  21061. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  21062. + case PREEMPTIRQSOFF_LATENCY:
  21063. + {
  21064. + int cpu;
  21065. +
  21066. + unregister_trace_preemptirqsoff_hist(
  21067. + probe_preemptirqsoff_hist, NULL);
  21068. + for_each_online_cpu(cpu) {
  21069. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  21070. + per_cpu(hist_irqsoff_counting,
  21071. + cpu) = 0;
  21072. +#endif
  21073. +#ifdef CONFIG_PREEMPT_OFF_HIST
  21074. + per_cpu(hist_preemptoff_counting,
  21075. + cpu) = 0;
  21076. +#endif
  21077. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  21078. + per_cpu(hist_preemptirqsoff_counting,
  21079. + cpu) = 0;
  21080. +#endif
  21081. + }
  21082. + }
  21083. + break;
  21084. +#endif
  21085. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21086. + case WAKEUP_LATENCY:
  21087. + {
  21088. + int cpu;
  21089. +
  21090. + unregister_trace_sched_wakeup(
  21091. + probe_wakeup_latency_hist_start, NULL);
  21092. + unregister_trace_sched_wakeup_new(
  21093. + probe_wakeup_latency_hist_start, NULL);
  21094. + unregister_trace_sched_switch(
  21095. + probe_wakeup_latency_hist_stop, NULL);
  21096. + unregister_trace_sched_migrate_task(
  21097. + probe_sched_migrate_task, NULL);
  21098. +
  21099. + for_each_online_cpu(cpu) {
  21100. + per_cpu(wakeup_task, cpu) = NULL;
  21101. + per_cpu(wakeup_sharedprio, cpu) = 0;
  21102. + }
  21103. + }
  21104. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21105. + timerandwakeup_enabled_data.enabled = 0;
  21106. +#endif
  21107. + break;
  21108. +#endif
  21109. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21110. + case MISSED_TIMER_OFFSETS:
  21111. + unregister_trace_hrtimer_interrupt(
  21112. + probe_hrtimer_interrupt, NULL);
  21113. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21114. + timerandwakeup_enabled_data.enabled = 0;
  21115. +#endif
  21116. + break;
  21117. +#endif
  21118. + default:
  21119. + break;
  21120. + }
  21121. + }
  21122. + ed->enabled = enable;
  21123. + return cnt;
  21124. +}
  21125. +
  21126. +static const struct file_operations latency_hist_reset_fops = {
  21127. + .open = tracing_open_generic,
  21128. + .write = latency_hist_reset,
  21129. +};
  21130. +
  21131. +static const struct file_operations enable_fops = {
  21132. + .open = tracing_open_generic,
  21133. + .read = show_enable,
  21134. + .write = do_enable,
  21135. +};
  21136. +
  21137. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  21138. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21139. +static const struct file_operations pid_fops = {
  21140. + .open = tracing_open_generic,
  21141. + .read = show_pid,
  21142. + .write = do_pid,
  21143. +};
  21144. +
  21145. +static const struct file_operations maxlatproc_fops = {
  21146. + .open = tracing_open_generic,
  21147. + .read = show_maxlatproc,
  21148. +};
  21149. +#endif
  21150. +
  21151. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  21152. +static notrace void probe_preemptirqsoff_hist(void *v, int reason,
  21153. + int starthist)
  21154. +{
  21155. + int cpu = raw_smp_processor_id();
  21156. + int time_set = 0;
  21157. +
  21158. + if (starthist) {
  21159. + cycle_t uninitialized_var(start);
  21160. +
  21161. + if (!preempt_count() && !irqs_disabled())
  21162. + return;
  21163. +
  21164. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  21165. + if ((reason == IRQS_OFF || reason == TRACE_START) &&
  21166. + !per_cpu(hist_irqsoff_counting, cpu)) {
  21167. + per_cpu(hist_irqsoff_counting, cpu) = 1;
  21168. + start = ftrace_now(cpu);
  21169. + time_set++;
  21170. + per_cpu(hist_irqsoff_start, cpu) = start;
  21171. + }
  21172. +#endif
  21173. +
  21174. +#ifdef CONFIG_PREEMPT_OFF_HIST
  21175. + if ((reason == PREEMPT_OFF || reason == TRACE_START) &&
  21176. + !per_cpu(hist_preemptoff_counting, cpu)) {
  21177. + per_cpu(hist_preemptoff_counting, cpu) = 1;
  21178. + if (!(time_set++))
  21179. + start = ftrace_now(cpu);
  21180. + per_cpu(hist_preemptoff_start, cpu) = start;
  21181. + }
  21182. +#endif
  21183. +
  21184. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  21185. + if (per_cpu(hist_irqsoff_counting, cpu) &&
  21186. + per_cpu(hist_preemptoff_counting, cpu) &&
  21187. + !per_cpu(hist_preemptirqsoff_counting, cpu)) {
  21188. + per_cpu(hist_preemptirqsoff_counting, cpu) = 1;
  21189. + if (!time_set)
  21190. + start = ftrace_now(cpu);
  21191. + per_cpu(hist_preemptirqsoff_start, cpu) = start;
  21192. + }
  21193. +#endif
  21194. + } else {
  21195. + cycle_t uninitialized_var(stop);
  21196. +
  21197. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  21198. + if ((reason == IRQS_ON || reason == TRACE_STOP) &&
  21199. + per_cpu(hist_irqsoff_counting, cpu)) {
  21200. + cycle_t start = per_cpu(hist_irqsoff_start, cpu);
  21201. +
  21202. + stop = ftrace_now(cpu);
  21203. + time_set++;
  21204. + if (start) {
  21205. + long latency = ((long) (stop - start)) /
  21206. + NSECS_PER_USECS;
  21207. +
  21208. + latency_hist(IRQSOFF_LATENCY, cpu, latency, 0,
  21209. + stop, NULL);
  21210. + }
  21211. + per_cpu(hist_irqsoff_counting, cpu) = 0;
  21212. + }
  21213. +#endif
  21214. +
  21215. +#ifdef CONFIG_PREEMPT_OFF_HIST
  21216. + if ((reason == PREEMPT_ON || reason == TRACE_STOP) &&
  21217. + per_cpu(hist_preemptoff_counting, cpu)) {
  21218. + cycle_t start = per_cpu(hist_preemptoff_start, cpu);
  21219. +
  21220. + if (!(time_set++))
  21221. + stop = ftrace_now(cpu);
  21222. + if (start) {
  21223. + long latency = ((long) (stop - start)) /
  21224. + NSECS_PER_USECS;
  21225. +
  21226. + latency_hist(PREEMPTOFF_LATENCY, cpu, latency,
  21227. + 0, stop, NULL);
  21228. + }
  21229. + per_cpu(hist_preemptoff_counting, cpu) = 0;
  21230. + }
  21231. +#endif
  21232. +
  21233. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  21234. + if ((!per_cpu(hist_irqsoff_counting, cpu) ||
  21235. + !per_cpu(hist_preemptoff_counting, cpu)) &&
  21236. + per_cpu(hist_preemptirqsoff_counting, cpu)) {
  21237. + cycle_t start = per_cpu(hist_preemptirqsoff_start, cpu);
  21238. +
  21239. + if (!time_set)
  21240. + stop = ftrace_now(cpu);
  21241. + if (start) {
  21242. + long latency = ((long) (stop - start)) /
  21243. + NSECS_PER_USECS;
  21244. +
  21245. + latency_hist(PREEMPTIRQSOFF_LATENCY, cpu,
  21246. + latency, 0, stop, NULL);
  21247. + }
  21248. + per_cpu(hist_preemptirqsoff_counting, cpu) = 0;
  21249. + }
  21250. +#endif
  21251. + }
  21252. +}
  21253. +#endif
  21254. +
  21255. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21256. +static DEFINE_RAW_SPINLOCK(wakeup_lock);
  21257. +static notrace void probe_sched_migrate_task(void *v, struct task_struct *task,
  21258. + int cpu)
  21259. +{
  21260. + int old_cpu = task_cpu(task);
  21261. +
  21262. + if (cpu != old_cpu) {
  21263. + unsigned long flags;
  21264. + struct task_struct *cpu_wakeup_task;
  21265. +
  21266. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  21267. +
  21268. + cpu_wakeup_task = per_cpu(wakeup_task, old_cpu);
  21269. + if (task == cpu_wakeup_task) {
  21270. + put_task_struct(cpu_wakeup_task);
  21271. + per_cpu(wakeup_task, old_cpu) = NULL;
  21272. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = task;
  21273. + get_task_struct(cpu_wakeup_task);
  21274. + }
  21275. +
  21276. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  21277. + }
  21278. +}
  21279. +
  21280. +static notrace void probe_wakeup_latency_hist_start(void *v,
  21281. + struct task_struct *p, int success)
  21282. +{
  21283. + unsigned long flags;
  21284. + struct task_struct *curr = current;
  21285. + int cpu = task_cpu(p);
  21286. + struct task_struct *cpu_wakeup_task;
  21287. +
  21288. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  21289. +
  21290. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  21291. +
  21292. + if (wakeup_pid) {
  21293. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  21294. + p->prio == curr->prio)
  21295. + per_cpu(wakeup_sharedprio, cpu) = 1;
  21296. + if (likely(wakeup_pid != task_pid_nr(p)))
  21297. + goto out;
  21298. + } else {
  21299. + if (likely(!rt_task(p)) ||
  21300. + (cpu_wakeup_task && p->prio > cpu_wakeup_task->prio) ||
  21301. + p->prio > curr->prio)
  21302. + goto out;
  21303. + if ((cpu_wakeup_task && p->prio == cpu_wakeup_task->prio) ||
  21304. + p->prio == curr->prio)
  21305. + per_cpu(wakeup_sharedprio, cpu) = 1;
  21306. + }
  21307. +
  21308. + if (cpu_wakeup_task)
  21309. + put_task_struct(cpu_wakeup_task);
  21310. + cpu_wakeup_task = per_cpu(wakeup_task, cpu) = p;
  21311. + get_task_struct(cpu_wakeup_task);
  21312. + cpu_wakeup_task->preempt_timestamp_hist =
  21313. + ftrace_now(raw_smp_processor_id());
  21314. +out:
  21315. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  21316. +}
  21317. +
  21318. +static notrace void probe_wakeup_latency_hist_stop(void *v,
  21319. + struct task_struct *prev, struct task_struct *next)
  21320. +{
  21321. + unsigned long flags;
  21322. + int cpu = task_cpu(next);
  21323. + long latency;
  21324. + cycle_t stop;
  21325. + struct task_struct *cpu_wakeup_task;
  21326. +
  21327. + raw_spin_lock_irqsave(&wakeup_lock, flags);
  21328. +
  21329. + cpu_wakeup_task = per_cpu(wakeup_task, cpu);
  21330. +
  21331. + if (cpu_wakeup_task == NULL)
  21332. + goto out;
  21333. +
  21334. + /* Already running? */
  21335. + if (unlikely(current == cpu_wakeup_task))
  21336. + goto out_reset;
  21337. +
  21338. + if (next != cpu_wakeup_task) {
  21339. + if (next->prio < cpu_wakeup_task->prio)
  21340. + goto out_reset;
  21341. +
  21342. + if (next->prio == cpu_wakeup_task->prio)
  21343. + per_cpu(wakeup_sharedprio, cpu) = 1;
  21344. +
  21345. + goto out;
  21346. + }
  21347. +
  21348. + if (current->prio == cpu_wakeup_task->prio)
  21349. + per_cpu(wakeup_sharedprio, cpu) = 1;
  21350. +
  21351. + /*
  21352. + * The task we are waiting for is about to be switched to.
  21353. + * Calculate latency and store it in histogram.
  21354. + */
  21355. + stop = ftrace_now(raw_smp_processor_id());
  21356. +
  21357. + latency = ((long) (stop - next->preempt_timestamp_hist)) /
  21358. + NSECS_PER_USECS;
  21359. +
  21360. + if (per_cpu(wakeup_sharedprio, cpu)) {
  21361. + latency_hist(WAKEUP_LATENCY_SHAREDPRIO, cpu, latency, 0, stop,
  21362. + next);
  21363. + per_cpu(wakeup_sharedprio, cpu) = 0;
  21364. + } else {
  21365. + latency_hist(WAKEUP_LATENCY, cpu, latency, 0, stop, next);
  21366. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21367. + if (timerandwakeup_enabled_data.enabled) {
  21368. + latency_hist(TIMERANDWAKEUP_LATENCY, cpu,
  21369. + next->timer_offset + latency, next->timer_offset,
  21370. + stop, next);
  21371. + }
  21372. +#endif
  21373. + }
  21374. +
  21375. +out_reset:
  21376. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21377. + next->timer_offset = 0;
  21378. +#endif
  21379. + put_task_struct(cpu_wakeup_task);
  21380. + per_cpu(wakeup_task, cpu) = NULL;
  21381. +out:
  21382. + raw_spin_unlock_irqrestore(&wakeup_lock, flags);
  21383. +}
  21384. +#endif
  21385. +
  21386. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21387. +static notrace void probe_hrtimer_interrupt(void *v, int cpu,
  21388. + long long latency_ns, struct task_struct *curr,
  21389. + struct task_struct *task)
  21390. +{
  21391. + if (latency_ns <= 0 && task != NULL && rt_task(task) &&
  21392. + (task->prio < curr->prio ||
  21393. + (task->prio == curr->prio &&
  21394. + !cpumask_test_cpu(cpu, &task->cpus_allowed)))) {
  21395. + long latency;
  21396. + cycle_t now;
  21397. +
  21398. + if (missed_timer_offsets_pid) {
  21399. + if (likely(missed_timer_offsets_pid !=
  21400. + task_pid_nr(task)))
  21401. + return;
  21402. + }
  21403. +
  21404. + now = ftrace_now(cpu);
  21405. + latency = (long) div_s64(-latency_ns, NSECS_PER_USECS);
  21406. + latency_hist(MISSED_TIMER_OFFSETS, cpu, latency, latency, now,
  21407. + task);
  21408. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21409. + task->timer_offset = latency;
  21410. +#endif
  21411. + }
  21412. +}
  21413. +#endif
  21414. +
  21415. +static __init int latency_hist_init(void)
  21416. +{
  21417. + struct dentry *latency_hist_root = NULL;
  21418. + struct dentry *dentry;
  21419. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21420. + struct dentry *dentry_sharedprio;
  21421. +#endif
  21422. + struct dentry *entry;
  21423. + struct dentry *enable_root;
  21424. + int i = 0;
  21425. + struct hist_data *my_hist;
  21426. + char name[64];
  21427. + char *cpufmt = "CPU%d";
  21428. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) || \
  21429. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21430. + char *cpufmt_maxlatproc = "max_latency-CPU%d";
  21431. + struct maxlatproc_data *mp = NULL;
  21432. +#endif
  21433. +
  21434. + dentry = tracing_init_dentry();
  21435. + latency_hist_root = debugfs_create_dir(latency_hist_dir_root, dentry);
  21436. + enable_root = debugfs_create_dir("enable", latency_hist_root);
  21437. +
  21438. +#ifdef CONFIG_INTERRUPT_OFF_HIST
  21439. + dentry = debugfs_create_dir(irqsoff_hist_dir, latency_hist_root);
  21440. + for_each_possible_cpu(i) {
  21441. + sprintf(name, cpufmt, i);
  21442. + entry = debugfs_create_file(name, 0444, dentry,
  21443. + &per_cpu(irqsoff_hist, i), &latency_hist_fops);
  21444. + my_hist = &per_cpu(irqsoff_hist, i);
  21445. + atomic_set(&my_hist->hist_mode, 1);
  21446. + my_hist->min_lat = LONG_MAX;
  21447. + }
  21448. + entry = debugfs_create_file("reset", 0644, dentry,
  21449. + (void *)IRQSOFF_LATENCY, &latency_hist_reset_fops);
  21450. +#endif
  21451. +
  21452. +#ifdef CONFIG_PREEMPT_OFF_HIST
  21453. + dentry = debugfs_create_dir(preemptoff_hist_dir,
  21454. + latency_hist_root);
  21455. + for_each_possible_cpu(i) {
  21456. + sprintf(name, cpufmt, i);
  21457. + entry = debugfs_create_file(name, 0444, dentry,
  21458. + &per_cpu(preemptoff_hist, i), &latency_hist_fops);
  21459. + my_hist = &per_cpu(preemptoff_hist, i);
  21460. + atomic_set(&my_hist->hist_mode, 1);
  21461. + my_hist->min_lat = LONG_MAX;
  21462. + }
  21463. + entry = debugfs_create_file("reset", 0644, dentry,
  21464. + (void *)PREEMPTOFF_LATENCY, &latency_hist_reset_fops);
  21465. +#endif
  21466. +
  21467. +#if defined(CONFIG_INTERRUPT_OFF_HIST) && defined(CONFIG_PREEMPT_OFF_HIST)
  21468. + dentry = debugfs_create_dir(preemptirqsoff_hist_dir,
  21469. + latency_hist_root);
  21470. + for_each_possible_cpu(i) {
  21471. + sprintf(name, cpufmt, i);
  21472. + entry = debugfs_create_file(name, 0444, dentry,
  21473. + &per_cpu(preemptirqsoff_hist, i), &latency_hist_fops);
  21474. + my_hist = &per_cpu(preemptirqsoff_hist, i);
  21475. + atomic_set(&my_hist->hist_mode, 1);
  21476. + my_hist->min_lat = LONG_MAX;
  21477. + }
  21478. + entry = debugfs_create_file("reset", 0644, dentry,
  21479. + (void *)PREEMPTIRQSOFF_LATENCY, &latency_hist_reset_fops);
  21480. +#endif
  21481. +
  21482. +#if defined(CONFIG_INTERRUPT_OFF_HIST) || defined(CONFIG_PREEMPT_OFF_HIST)
  21483. + entry = debugfs_create_file("preemptirqsoff", 0644,
  21484. + enable_root, (void *)&preemptirqsoff_enabled_data,
  21485. + &enable_fops);
  21486. +#endif
  21487. +
  21488. +#ifdef CONFIG_WAKEUP_LATENCY_HIST
  21489. + dentry = debugfs_create_dir(wakeup_latency_hist_dir,
  21490. + latency_hist_root);
  21491. + dentry_sharedprio = debugfs_create_dir(
  21492. + wakeup_latency_hist_dir_sharedprio, dentry);
  21493. + for_each_possible_cpu(i) {
  21494. + sprintf(name, cpufmt, i);
  21495. +
  21496. + entry = debugfs_create_file(name, 0444, dentry,
  21497. + &per_cpu(wakeup_latency_hist, i),
  21498. + &latency_hist_fops);
  21499. + my_hist = &per_cpu(wakeup_latency_hist, i);
  21500. + atomic_set(&my_hist->hist_mode, 1);
  21501. + my_hist->min_lat = LONG_MAX;
  21502. +
  21503. + entry = debugfs_create_file(name, 0444, dentry_sharedprio,
  21504. + &per_cpu(wakeup_latency_hist_sharedprio, i),
  21505. + &latency_hist_fops);
  21506. + my_hist = &per_cpu(wakeup_latency_hist_sharedprio, i);
  21507. + atomic_set(&my_hist->hist_mode, 1);
  21508. + my_hist->min_lat = LONG_MAX;
  21509. +
  21510. + sprintf(name, cpufmt_maxlatproc, i);
  21511. +
  21512. + mp = &per_cpu(wakeup_maxlatproc, i);
  21513. + entry = debugfs_create_file(name, 0444, dentry, mp,
  21514. + &maxlatproc_fops);
  21515. + clear_maxlatprocdata(mp);
  21516. +
  21517. + mp = &per_cpu(wakeup_maxlatproc_sharedprio, i);
  21518. + entry = debugfs_create_file(name, 0444, dentry_sharedprio, mp,
  21519. + &maxlatproc_fops);
  21520. + clear_maxlatprocdata(mp);
  21521. + }
  21522. + entry = debugfs_create_file("pid", 0644, dentry,
  21523. + (void *)&wakeup_pid, &pid_fops);
  21524. + entry = debugfs_create_file("reset", 0644, dentry,
  21525. + (void *)WAKEUP_LATENCY, &latency_hist_reset_fops);
  21526. + entry = debugfs_create_file("reset", 0644, dentry_sharedprio,
  21527. + (void *)WAKEUP_LATENCY_SHAREDPRIO, &latency_hist_reset_fops);
  21528. + entry = debugfs_create_file("wakeup", 0644,
  21529. + enable_root, (void *)&wakeup_latency_enabled_data,
  21530. + &enable_fops);
  21531. +#endif
  21532. +
  21533. +#ifdef CONFIG_MISSED_TIMER_OFFSETS_HIST
  21534. + dentry = debugfs_create_dir(missed_timer_offsets_dir,
  21535. + latency_hist_root);
  21536. + for_each_possible_cpu(i) {
  21537. + sprintf(name, cpufmt, i);
  21538. + entry = debugfs_create_file(name, 0444, dentry,
  21539. + &per_cpu(missed_timer_offsets, i), &latency_hist_fops);
  21540. + my_hist = &per_cpu(missed_timer_offsets, i);
  21541. + atomic_set(&my_hist->hist_mode, 1);
  21542. + my_hist->min_lat = LONG_MAX;
  21543. +
  21544. + sprintf(name, cpufmt_maxlatproc, i);
  21545. + mp = &per_cpu(missed_timer_offsets_maxlatproc, i);
  21546. + entry = debugfs_create_file(name, 0444, dentry, mp,
  21547. + &maxlatproc_fops);
  21548. + clear_maxlatprocdata(mp);
  21549. + }
  21550. + entry = debugfs_create_file("pid", 0644, dentry,
  21551. + (void *)&missed_timer_offsets_pid, &pid_fops);
  21552. + entry = debugfs_create_file("reset", 0644, dentry,
  21553. + (void *)MISSED_TIMER_OFFSETS, &latency_hist_reset_fops);
  21554. + entry = debugfs_create_file("missed_timer_offsets", 0644,
  21555. + enable_root, (void *)&missed_timer_offsets_enabled_data,
  21556. + &enable_fops);
  21557. +#endif
  21558. +
  21559. +#if defined(CONFIG_WAKEUP_LATENCY_HIST) && \
  21560. + defined(CONFIG_MISSED_TIMER_OFFSETS_HIST)
  21561. + dentry = debugfs_create_dir(timerandwakeup_latency_hist_dir,
  21562. + latency_hist_root);
  21563. + for_each_possible_cpu(i) {
  21564. + sprintf(name, cpufmt, i);
  21565. + entry = debugfs_create_file(name, 0444, dentry,
  21566. + &per_cpu(timerandwakeup_latency_hist, i),
  21567. + &latency_hist_fops);
  21568. + my_hist = &per_cpu(timerandwakeup_latency_hist, i);
  21569. + atomic_set(&my_hist->hist_mode, 1);
  21570. + my_hist->min_lat = LONG_MAX;
  21571. +
  21572. + sprintf(name, cpufmt_maxlatproc, i);
  21573. + mp = &per_cpu(timerandwakeup_maxlatproc, i);
  21574. + entry = debugfs_create_file(name, 0444, dentry, mp,
  21575. + &maxlatproc_fops);
  21576. + clear_maxlatprocdata(mp);
  21577. + }
  21578. + entry = debugfs_create_file("reset", 0644, dentry,
  21579. + (void *)TIMERANDWAKEUP_LATENCY, &latency_hist_reset_fops);
  21580. + entry = debugfs_create_file("timerandwakeup", 0644,
  21581. + enable_root, (void *)&timerandwakeup_enabled_data,
  21582. + &enable_fops);
  21583. +#endif
  21584. + return 0;
  21585. +}
  21586. +
  21587. +device_initcall(latency_hist_init);
  21588. diff -Nur linux-4.1.6.orig/kernel/trace/Makefile linux-4.1.6/kernel/trace/Makefile
  21589. --- linux-4.1.6.orig/kernel/trace/Makefile 2015-08-17 05:52:51.000000000 +0200
  21590. +++ linux-4.1.6/kernel/trace/Makefile 2015-09-08 23:49:08.125865168 +0200
  21591. @@ -36,6 +36,10 @@
  21592. obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
  21593. obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
  21594. obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
  21595. +obj-$(CONFIG_INTERRUPT_OFF_HIST) += latency_hist.o
  21596. +obj-$(CONFIG_PREEMPT_OFF_HIST) += latency_hist.o
  21597. +obj-$(CONFIG_WAKEUP_LATENCY_HIST) += latency_hist.o
  21598. +obj-$(CONFIG_MISSED_TIMER_OFFSETS_HIST) += latency_hist.o
  21599. obj-$(CONFIG_NOP_TRACER) += trace_nop.o
  21600. obj-$(CONFIG_STACK_TRACER) += trace_stack.o
  21601. obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
  21602. diff -Nur linux-4.1.6.orig/kernel/trace/trace.c linux-4.1.6/kernel/trace/trace.c
  21603. --- linux-4.1.6.orig/kernel/trace/trace.c 2015-08-17 05:52:51.000000000 +0200
  21604. +++ linux-4.1.6/kernel/trace/trace.c 2015-09-08 23:49:08.125865168 +0200
  21605. @@ -1630,6 +1630,7 @@
  21606. struct task_struct *tsk = current;
  21607. entry->preempt_count = pc & 0xff;
  21608. + entry->preempt_lazy_count = preempt_lazy_count();
  21609. entry->pid = (tsk) ? tsk->pid : 0;
  21610. entry->flags =
  21611. #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT
  21612. @@ -1639,8 +1640,11 @@
  21613. #endif
  21614. ((pc & HARDIRQ_MASK) ? TRACE_FLAG_HARDIRQ : 0) |
  21615. ((pc & SOFTIRQ_MASK) ? TRACE_FLAG_SOFTIRQ : 0) |
  21616. - (tif_need_resched() ? TRACE_FLAG_NEED_RESCHED : 0) |
  21617. + (tif_need_resched_now() ? TRACE_FLAG_NEED_RESCHED : 0) |
  21618. + (need_resched_lazy() ? TRACE_FLAG_NEED_RESCHED_LAZY : 0) |
  21619. (test_preempt_need_resched() ? TRACE_FLAG_PREEMPT_RESCHED : 0);
  21620. +
  21621. + entry->migrate_disable = (tsk) ? __migrate_disabled(tsk) & 0xFF : 0;
  21622. }
  21623. EXPORT_SYMBOL_GPL(tracing_generic_entry_update);
  21624. @@ -2558,14 +2562,17 @@
  21625. static void print_lat_help_header(struct seq_file *m)
  21626. {
  21627. - seq_puts(m, "# _------=> CPU# \n"
  21628. - "# / _-----=> irqs-off \n"
  21629. - "# | / _----=> need-resched \n"
  21630. - "# || / _---=> hardirq/softirq \n"
  21631. - "# ||| / _--=> preempt-depth \n"
  21632. - "# |||| / delay \n"
  21633. - "# cmd pid ||||| time | caller \n"
  21634. - "# \\ / ||||| \\ | / \n");
  21635. + seq_puts(m, "# _--------=> CPU# \n"
  21636. + "# / _-------=> irqs-off \n"
  21637. + "# | / _------=> need-resched \n"
  21638. + "# || / _-----=> need-resched_lazy \n"
  21639. + "# ||| / _----=> hardirq/softirq \n"
  21640. + "# |||| / _---=> preempt-depth \n"
  21641. + "# ||||| / _--=> preempt-lazy-depth\n"
  21642. + "# |||||| / _-=> migrate-disable \n"
  21643. + "# ||||||| / delay \n"
  21644. + "# cmd pid |||||||| time | caller \n"
  21645. + "# \\ / |||||||| \\ | / \n");
  21646. }
  21647. static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
  21648. @@ -2591,11 +2598,14 @@
  21649. print_event_info(buf, m);
  21650. seq_puts(m, "# _-----=> irqs-off\n"
  21651. "# / _----=> need-resched\n"
  21652. - "# | / _---=> hardirq/softirq\n"
  21653. - "# || / _--=> preempt-depth\n"
  21654. - "# ||| / delay\n"
  21655. - "# TASK-PID CPU# |||| TIMESTAMP FUNCTION\n"
  21656. - "# | | | |||| | |\n");
  21657. + "# |/ _-----=> need-resched_lazy\n"
  21658. + "# || / _---=> hardirq/softirq\n"
  21659. + "# ||| / _--=> preempt-depth\n"
  21660. + "# |||| /_--=> preempt-lazy-depth\n"
  21661. + "# ||||| _-=> migrate-disable \n"
  21662. + "# ||||| / delay\n"
  21663. + "# TASK-PID CPU# |||||| TIMESTAMP FUNCTION\n"
  21664. + "# | | | |||||| | |\n");
  21665. }
  21666. void
  21667. diff -Nur linux-4.1.6.orig/kernel/trace/trace_events.c linux-4.1.6/kernel/trace/trace_events.c
  21668. --- linux-4.1.6.orig/kernel/trace/trace_events.c 2015-08-17 05:52:51.000000000 +0200
  21669. +++ linux-4.1.6/kernel/trace/trace_events.c 2015-09-08 23:49:08.125865168 +0200
  21670. @@ -162,6 +162,8 @@
  21671. __common_field(unsigned char, flags);
  21672. __common_field(unsigned char, preempt_count);
  21673. __common_field(int, pid);
  21674. + __common_field(unsigned short, migrate_disable);
  21675. + __common_field(unsigned short, padding);
  21676. return ret;
  21677. }
  21678. diff -Nur linux-4.1.6.orig/kernel/trace/trace.h linux-4.1.6/kernel/trace/trace.h
  21679. --- linux-4.1.6.orig/kernel/trace/trace.h 2015-08-17 05:52:51.000000000 +0200
  21680. +++ linux-4.1.6/kernel/trace/trace.h 2015-09-08 23:49:08.125865168 +0200
  21681. @@ -120,6 +120,7 @@
  21682. * NEED_RESCHED - reschedule is requested
  21683. * HARDIRQ - inside an interrupt handler
  21684. * SOFTIRQ - inside a softirq handler
  21685. + * NEED_RESCHED_LAZY - lazy reschedule is requested
  21686. */
  21687. enum trace_flag_type {
  21688. TRACE_FLAG_IRQS_OFF = 0x01,
  21689. @@ -128,6 +129,7 @@
  21690. TRACE_FLAG_HARDIRQ = 0x08,
  21691. TRACE_FLAG_SOFTIRQ = 0x10,
  21692. TRACE_FLAG_PREEMPT_RESCHED = 0x20,
  21693. + TRACE_FLAG_NEED_RESCHED_LAZY = 0x40,
  21694. };
  21695. #define TRACE_BUF_SIZE 1024
  21696. diff -Nur linux-4.1.6.orig/kernel/trace/trace_irqsoff.c linux-4.1.6/kernel/trace/trace_irqsoff.c
  21697. --- linux-4.1.6.orig/kernel/trace/trace_irqsoff.c 2015-08-17 05:52:51.000000000 +0200
  21698. +++ linux-4.1.6/kernel/trace/trace_irqsoff.c 2015-09-08 23:49:08.129864725 +0200
  21699. @@ -13,6 +13,7 @@
  21700. #include <linux/uaccess.h>
  21701. #include <linux/module.h>
  21702. #include <linux/ftrace.h>
  21703. +#include <trace/events/hist.h>
  21704. #include "trace.h"
  21705. @@ -433,11 +434,13 @@
  21706. {
  21707. if (preempt_trace() || irq_trace())
  21708. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  21709. + trace_preemptirqsoff_hist(TRACE_START, 1);
  21710. }
  21711. EXPORT_SYMBOL_GPL(start_critical_timings);
  21712. void stop_critical_timings(void)
  21713. {
  21714. + trace_preemptirqsoff_hist(TRACE_STOP, 0);
  21715. if (preempt_trace() || irq_trace())
  21716. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  21717. }
  21718. @@ -447,6 +450,7 @@
  21719. #ifdef CONFIG_PROVE_LOCKING
  21720. void time_hardirqs_on(unsigned long a0, unsigned long a1)
  21721. {
  21722. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  21723. if (!preempt_trace() && irq_trace())
  21724. stop_critical_timing(a0, a1);
  21725. }
  21726. @@ -455,6 +459,7 @@
  21727. {
  21728. if (!preempt_trace() && irq_trace())
  21729. start_critical_timing(a0, a1);
  21730. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  21731. }
  21732. #else /* !CONFIG_PROVE_LOCKING */
  21733. @@ -480,6 +485,7 @@
  21734. */
  21735. void trace_hardirqs_on(void)
  21736. {
  21737. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  21738. if (!preempt_trace() && irq_trace())
  21739. stop_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  21740. }
  21741. @@ -489,11 +495,13 @@
  21742. {
  21743. if (!preempt_trace() && irq_trace())
  21744. start_critical_timing(CALLER_ADDR0, CALLER_ADDR1);
  21745. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  21746. }
  21747. EXPORT_SYMBOL(trace_hardirqs_off);
  21748. __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
  21749. {
  21750. + trace_preemptirqsoff_hist(IRQS_ON, 0);
  21751. if (!preempt_trace() && irq_trace())
  21752. stop_critical_timing(CALLER_ADDR0, caller_addr);
  21753. }
  21754. @@ -503,6 +511,7 @@
  21755. {
  21756. if (!preempt_trace() && irq_trace())
  21757. start_critical_timing(CALLER_ADDR0, caller_addr);
  21758. + trace_preemptirqsoff_hist(IRQS_OFF, 1);
  21759. }
  21760. EXPORT_SYMBOL(trace_hardirqs_off_caller);
  21761. @@ -512,12 +521,14 @@
  21762. #ifdef CONFIG_PREEMPT_TRACER
  21763. void trace_preempt_on(unsigned long a0, unsigned long a1)
  21764. {
  21765. + trace_preemptirqsoff_hist(PREEMPT_ON, 0);
  21766. if (preempt_trace() && !irq_trace())
  21767. stop_critical_timing(a0, a1);
  21768. }
  21769. void trace_preempt_off(unsigned long a0, unsigned long a1)
  21770. {
  21771. + trace_preemptirqsoff_hist(PREEMPT_ON, 1);
  21772. if (preempt_trace() && !irq_trace())
  21773. start_critical_timing(a0, a1);
  21774. }
  21775. diff -Nur linux-4.1.6.orig/kernel/trace/trace_output.c linux-4.1.6/kernel/trace/trace_output.c
  21776. --- linux-4.1.6.orig/kernel/trace/trace_output.c 2015-08-17 05:52:51.000000000 +0200
  21777. +++ linux-4.1.6/kernel/trace/trace_output.c 2015-09-08 23:49:08.137863836 +0200
  21778. @@ -430,6 +430,7 @@
  21779. {
  21780. char hardsoft_irq;
  21781. char need_resched;
  21782. + char need_resched_lazy;
  21783. char irqs_off;
  21784. int hardirq;
  21785. int softirq;
  21786. @@ -457,6 +458,8 @@
  21787. need_resched = '.';
  21788. break;
  21789. }
  21790. + need_resched_lazy =
  21791. + (entry->flags & TRACE_FLAG_NEED_RESCHED_LAZY) ? 'L' : '.';
  21792. hardsoft_irq =
  21793. (hardirq && softirq) ? 'H' :
  21794. @@ -464,14 +467,25 @@
  21795. softirq ? 's' :
  21796. '.';
  21797. - trace_seq_printf(s, "%c%c%c",
  21798. - irqs_off, need_resched, hardsoft_irq);
  21799. + trace_seq_printf(s, "%c%c%c%c",
  21800. + irqs_off, need_resched, need_resched_lazy,
  21801. + hardsoft_irq);
  21802. if (entry->preempt_count)
  21803. trace_seq_printf(s, "%x", entry->preempt_count);
  21804. else
  21805. trace_seq_putc(s, '.');
  21806. + if (entry->preempt_lazy_count)
  21807. + trace_seq_printf(s, "%x", entry->preempt_lazy_count);
  21808. + else
  21809. + trace_seq_putc(s, '.');
  21810. +
  21811. + if (entry->migrate_disable)
  21812. + trace_seq_printf(s, "%x", entry->migrate_disable);
  21813. + else
  21814. + trace_seq_putc(s, '.');
  21815. +
  21816. return !trace_seq_has_overflowed(s);
  21817. }
  21818. diff -Nur linux-4.1.6.orig/kernel/user.c linux-4.1.6/kernel/user.c
  21819. --- linux-4.1.6.orig/kernel/user.c 2015-08-17 05:52:51.000000000 +0200
  21820. +++ linux-4.1.6/kernel/user.c 2015-09-08 23:49:08.137863836 +0200
  21821. @@ -161,11 +161,11 @@
  21822. if (!up)
  21823. return;
  21824. - local_irq_save(flags);
  21825. + local_irq_save_nort(flags);
  21826. if (atomic_dec_and_lock(&up->__count, &uidhash_lock))
  21827. free_user(up, flags);
  21828. else
  21829. - local_irq_restore(flags);
  21830. + local_irq_restore_nort(flags);
  21831. }
  21832. struct user_struct *alloc_uid(kuid_t uid)
  21833. diff -Nur linux-4.1.6.orig/kernel/watchdog.c linux-4.1.6/kernel/watchdog.c
  21834. --- linux-4.1.6.orig/kernel/watchdog.c 2015-08-17 05:52:51.000000000 +0200
  21835. +++ linux-4.1.6/kernel/watchdog.c 2015-09-08 23:49:08.421832347 +0200
  21836. @@ -262,6 +262,8 @@
  21837. #ifdef CONFIG_HARDLOCKUP_DETECTOR
  21838. +static DEFINE_RAW_SPINLOCK(watchdog_output_lock);
  21839. +
  21840. static struct perf_event_attr wd_hw_attr = {
  21841. .type = PERF_TYPE_HARDWARE,
  21842. .config = PERF_COUNT_HW_CPU_CYCLES,
  21843. @@ -295,13 +297,21 @@
  21844. /* only print hardlockups once */
  21845. if (__this_cpu_read(hard_watchdog_warn) == true)
  21846. return;
  21847. + /*
  21848. + * If early-printk is enabled then make sure we do not
  21849. + * lock up in printk() and kill console logging:
  21850. + */
  21851. + printk_kill();
  21852. - if (hardlockup_panic)
  21853. + if (hardlockup_panic) {
  21854. panic("Watchdog detected hard LOCKUP on cpu %d",
  21855. this_cpu);
  21856. - else
  21857. + } else {
  21858. + raw_spin_lock(&watchdog_output_lock);
  21859. WARN(1, "Watchdog detected hard LOCKUP on cpu %d",
  21860. this_cpu);
  21861. + raw_spin_unlock(&watchdog_output_lock);
  21862. + }
  21863. __this_cpu_write(hard_watchdog_warn, true);
  21864. return;
  21865. @@ -444,6 +454,7 @@
  21866. /* kick off the timer for the hardlockup detector */
  21867. hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  21868. hrtimer->function = watchdog_timer_fn;
  21869. + hrtimer->irqsafe = 1;
  21870. /* Enable the perf event */
  21871. watchdog_nmi_enable(cpu);
  21872. diff -Nur linux-4.1.6.orig/kernel/workqueue.c linux-4.1.6/kernel/workqueue.c
  21873. --- linux-4.1.6.orig/kernel/workqueue.c 2015-08-17 05:52:51.000000000 +0200
  21874. +++ linux-4.1.6/kernel/workqueue.c 2015-09-08 23:49:08.425831903 +0200
  21875. @@ -48,6 +48,8 @@
  21876. #include <linux/nodemask.h>
  21877. #include <linux/moduleparam.h>
  21878. #include <linux/uaccess.h>
  21879. +#include <linux/locallock.h>
  21880. +#include <linux/delay.h>
  21881. #include "workqueue_internal.h"
  21882. @@ -121,15 +123,20 @@
  21883. * cpu or grabbing pool->lock is enough for read access. If
  21884. * POOL_DISASSOCIATED is set, it's identical to L.
  21885. *
  21886. + * On RT we need the extra protection via rt_lock_idle_list() for
  21887. + * the list manipulations against read access from
  21888. + * wq_worker_sleeping(). All other places are nicely serialized via
  21889. + * pool->lock.
  21890. + *
  21891. * A: pool->attach_mutex protected.
  21892. *
  21893. * PL: wq_pool_mutex protected.
  21894. *
  21895. - * PR: wq_pool_mutex protected for writes. Sched-RCU protected for reads.
  21896. + * PR: wq_pool_mutex protected for writes. RCU protected for reads.
  21897. *
  21898. * WQ: wq->mutex protected.
  21899. *
  21900. - * WR: wq->mutex protected for writes. Sched-RCU protected for reads.
  21901. + * WR: wq->mutex protected for writes. RCU protected for reads.
  21902. *
  21903. * MD: wq_mayday_lock protected.
  21904. */
  21905. @@ -178,7 +185,7 @@
  21906. atomic_t nr_running ____cacheline_aligned_in_smp;
  21907. /*
  21908. - * Destruction of pool is sched-RCU protected to allow dereferences
  21909. + * Destruction of pool is RCU protected to allow dereferences
  21910. * from get_work_pool().
  21911. */
  21912. struct rcu_head rcu;
  21913. @@ -207,7 +214,7 @@
  21914. /*
  21915. * Release of unbound pwq is punted to system_wq. See put_pwq()
  21916. * and pwq_unbound_release_workfn() for details. pool_workqueue
  21917. - * itself is also sched-RCU protected so that the first pwq can be
  21918. + * itself is also RCU protected so that the first pwq can be
  21919. * determined without grabbing wq->mutex.
  21920. */
  21921. struct work_struct unbound_release_work;
  21922. @@ -329,6 +336,8 @@
  21923. struct workqueue_struct *system_freezable_power_efficient_wq __read_mostly;
  21924. EXPORT_SYMBOL_GPL(system_freezable_power_efficient_wq);
  21925. +static DEFINE_LOCAL_IRQ_LOCK(pendingb_lock);
  21926. +
  21927. static int worker_thread(void *__worker);
  21928. static void copy_workqueue_attrs(struct workqueue_attrs *to,
  21929. const struct workqueue_attrs *from);
  21930. @@ -338,14 +347,14 @@
  21931. #include <trace/events/workqueue.h>
  21932. #define assert_rcu_or_pool_mutex() \
  21933. - rcu_lockdep_assert(rcu_read_lock_sched_held() || \
  21934. + rcu_lockdep_assert(rcu_read_lock_held() || \
  21935. lockdep_is_held(&wq_pool_mutex), \
  21936. - "sched RCU or wq_pool_mutex should be held")
  21937. + "RCU or wq_pool_mutex should be held")
  21938. #define assert_rcu_or_wq_mutex(wq) \
  21939. - rcu_lockdep_assert(rcu_read_lock_sched_held() || \
  21940. + rcu_lockdep_assert(rcu_read_lock_held() || \
  21941. lockdep_is_held(&wq->mutex), \
  21942. - "sched RCU or wq->mutex should be held")
  21943. + "RCU or wq->mutex should be held")
  21944. #define for_each_cpu_worker_pool(pool, cpu) \
  21945. for ((pool) = &per_cpu(cpu_worker_pools, cpu)[0]; \
  21946. @@ -357,7 +366,7 @@
  21947. * @pool: iteration cursor
  21948. * @pi: integer used for iteration
  21949. *
  21950. - * This must be called either with wq_pool_mutex held or sched RCU read
  21951. + * This must be called either with wq_pool_mutex held or RCU read
  21952. * locked. If the pool needs to be used beyond the locking in effect, the
  21953. * caller is responsible for guaranteeing that the pool stays online.
  21954. *
  21955. @@ -389,7 +398,7 @@
  21956. * @pwq: iteration cursor
  21957. * @wq: the target workqueue
  21958. *
  21959. - * This must be called either with wq->mutex held or sched RCU read locked.
  21960. + * This must be called either with wq->mutex held or RCU read locked.
  21961. * If the pwq needs to be used beyond the locking in effect, the caller is
  21962. * responsible for guaranteeing that the pwq stays online.
  21963. *
  21964. @@ -401,6 +410,31 @@
  21965. if (({ assert_rcu_or_wq_mutex(wq); false; })) { } \
  21966. else
  21967. +#ifdef CONFIG_PREEMPT_RT_BASE
  21968. +static inline void rt_lock_idle_list(struct worker_pool *pool)
  21969. +{
  21970. + preempt_disable();
  21971. +}
  21972. +static inline void rt_unlock_idle_list(struct worker_pool *pool)
  21973. +{
  21974. + preempt_enable();
  21975. +}
  21976. +static inline void sched_lock_idle_list(struct worker_pool *pool) { }
  21977. +static inline void sched_unlock_idle_list(struct worker_pool *pool) { }
  21978. +#else
  21979. +static inline void rt_lock_idle_list(struct worker_pool *pool) { }
  21980. +static inline void rt_unlock_idle_list(struct worker_pool *pool) { }
  21981. +static inline void sched_lock_idle_list(struct worker_pool *pool)
  21982. +{
  21983. + spin_lock_irq(&pool->lock);
  21984. +}
  21985. +static inline void sched_unlock_idle_list(struct worker_pool *pool)
  21986. +{
  21987. + spin_unlock_irq(&pool->lock);
  21988. +}
  21989. +#endif
  21990. +
  21991. +
  21992. #ifdef CONFIG_DEBUG_OBJECTS_WORK
  21993. static struct debug_obj_descr work_debug_descr;
  21994. @@ -551,7 +585,7 @@
  21995. * @wq: the target workqueue
  21996. * @node: the node ID
  21997. *
  21998. - * This must be called either with pwq_lock held or sched RCU read locked.
  21999. + * This must be called either with pwq_lock held or RCU read locked.
  22000. * If the pwq needs to be used beyond the locking in effect, the caller is
  22001. * responsible for guaranteeing that the pwq stays online.
  22002. *
  22003. @@ -655,8 +689,8 @@
  22004. * @work: the work item of interest
  22005. *
  22006. * Pools are created and destroyed under wq_pool_mutex, and allows read
  22007. - * access under sched-RCU read lock. As such, this function should be
  22008. - * called under wq_pool_mutex or with preemption disabled.
  22009. + * access under RCU read lock. As such, this function should be
  22010. + * called under wq_pool_mutex or inside of a rcu_read_lock() region.
  22011. *
  22012. * All fields of the returned pool are accessible as long as the above
  22013. * mentioned locking is in effect. If the returned pool needs to be used
  22014. @@ -793,51 +827,44 @@
  22015. */
  22016. static void wake_up_worker(struct worker_pool *pool)
  22017. {
  22018. - struct worker *worker = first_idle_worker(pool);
  22019. + struct worker *worker;
  22020. +
  22021. + rt_lock_idle_list(pool);
  22022. +
  22023. + worker = first_idle_worker(pool);
  22024. if (likely(worker))
  22025. wake_up_process(worker->task);
  22026. +
  22027. + rt_unlock_idle_list(pool);
  22028. }
  22029. /**
  22030. - * wq_worker_waking_up - a worker is waking up
  22031. - * @task: task waking up
  22032. - * @cpu: CPU @task is waking up to
  22033. + * wq_worker_running - a worker is running again
  22034. + * @task: task returning from sleep
  22035. *
  22036. - * This function is called during try_to_wake_up() when a worker is
  22037. - * being awoken.
  22038. - *
  22039. - * CONTEXT:
  22040. - * spin_lock_irq(rq->lock)
  22041. + * This function is called when a worker returns from schedule()
  22042. */
  22043. -void wq_worker_waking_up(struct task_struct *task, int cpu)
  22044. +void wq_worker_running(struct task_struct *task)
  22045. {
  22046. struct worker *worker = kthread_data(task);
  22047. - if (!(worker->flags & WORKER_NOT_RUNNING)) {
  22048. - WARN_ON_ONCE(worker->pool->cpu != cpu);
  22049. + if (!worker->sleeping)
  22050. + return;
  22051. + if (!(worker->flags & WORKER_NOT_RUNNING))
  22052. atomic_inc(&worker->pool->nr_running);
  22053. - }
  22054. + worker->sleeping = 0;
  22055. }
  22056. /**
  22057. * wq_worker_sleeping - a worker is going to sleep
  22058. * @task: task going to sleep
  22059. - * @cpu: CPU in question, must be the current CPU number
  22060. - *
  22061. - * This function is called during schedule() when a busy worker is
  22062. - * going to sleep. Worker on the same cpu can be woken up by
  22063. - * returning pointer to its task.
  22064. - *
  22065. - * CONTEXT:
  22066. - * spin_lock_irq(rq->lock)
  22067. - *
  22068. - * Return:
  22069. - * Worker task on @cpu to wake up, %NULL if none.
  22070. + * This function is called from schedule() when a busy worker is
  22071. + * going to sleep.
  22072. */
  22073. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu)
  22074. +void wq_worker_sleeping(struct task_struct *task)
  22075. {
  22076. - struct worker *worker = kthread_data(task), *to_wakeup = NULL;
  22077. + struct worker *worker = kthread_data(task);
  22078. struct worker_pool *pool;
  22079. /*
  22080. @@ -846,29 +873,26 @@
  22081. * checking NOT_RUNNING.
  22082. */
  22083. if (worker->flags & WORKER_NOT_RUNNING)
  22084. - return NULL;
  22085. + return;
  22086. pool = worker->pool;
  22087. - /* this can only happen on the local cpu */
  22088. - if (WARN_ON_ONCE(cpu != raw_smp_processor_id() || pool->cpu != cpu))
  22089. - return NULL;
  22090. + if (WARN_ON_ONCE(worker->sleeping))
  22091. + return;
  22092. +
  22093. + worker->sleeping = 1;
  22094. /*
  22095. * The counterpart of the following dec_and_test, implied mb,
  22096. * worklist not empty test sequence is in insert_work().
  22097. * Please read comment there.
  22098. - *
  22099. - * NOT_RUNNING is clear. This means that we're bound to and
  22100. - * running on the local cpu w/ rq lock held and preemption
  22101. - * disabled, which in turn means that none else could be
  22102. - * manipulating idle_list, so dereferencing idle_list without pool
  22103. - * lock is safe.
  22104. */
  22105. if (atomic_dec_and_test(&pool->nr_running) &&
  22106. - !list_empty(&pool->worklist))
  22107. - to_wakeup = first_idle_worker(pool);
  22108. - return to_wakeup ? to_wakeup->task : NULL;
  22109. + !list_empty(&pool->worklist)) {
  22110. + sched_lock_idle_list(pool);
  22111. + wake_up_worker(pool);
  22112. + sched_unlock_idle_list(pool);
  22113. + }
  22114. }
  22115. /**
  22116. @@ -1062,12 +1086,12 @@
  22117. {
  22118. if (pwq) {
  22119. /*
  22120. - * As both pwqs and pools are sched-RCU protected, the
  22121. + * As both pwqs and pools are RCU protected, the
  22122. * following lock operations are safe.
  22123. */
  22124. - spin_lock_irq(&pwq->pool->lock);
  22125. + local_spin_lock_irq(pendingb_lock, &pwq->pool->lock);
  22126. put_pwq(pwq);
  22127. - spin_unlock_irq(&pwq->pool->lock);
  22128. + local_spin_unlock_irq(pendingb_lock, &pwq->pool->lock);
  22129. }
  22130. }
  22131. @@ -1169,7 +1193,7 @@
  22132. struct worker_pool *pool;
  22133. struct pool_workqueue *pwq;
  22134. - local_irq_save(*flags);
  22135. + local_lock_irqsave(pendingb_lock, *flags);
  22136. /* try to steal the timer if it exists */
  22137. if (is_dwork) {
  22138. @@ -1188,6 +1212,7 @@
  22139. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)))
  22140. return 0;
  22141. + rcu_read_lock();
  22142. /*
  22143. * The queueing is in progress, or it is already queued. Try to
  22144. * steal it from ->worklist without clearing WORK_STRUCT_PENDING.
  22145. @@ -1226,14 +1251,16 @@
  22146. set_work_pool_and_keep_pending(work, pool->id);
  22147. spin_unlock(&pool->lock);
  22148. + rcu_read_unlock();
  22149. return 1;
  22150. }
  22151. spin_unlock(&pool->lock);
  22152. fail:
  22153. - local_irq_restore(*flags);
  22154. + rcu_read_unlock();
  22155. + local_unlock_irqrestore(pendingb_lock, *flags);
  22156. if (work_is_canceling(work))
  22157. return -ENOENT;
  22158. - cpu_relax();
  22159. + cpu_chill();
  22160. return -EAGAIN;
  22161. }
  22162. @@ -1302,7 +1329,7 @@
  22163. * queued or lose PENDING. Grabbing PENDING and queueing should
  22164. * happen with IRQ disabled.
  22165. */
  22166. - WARN_ON_ONCE(!irqs_disabled());
  22167. + WARN_ON_ONCE_NONRT(!irqs_disabled());
  22168. debug_work_activate(work);
  22169. @@ -1310,6 +1337,8 @@
  22170. if (unlikely(wq->flags & __WQ_DRAINING) &&
  22171. WARN_ON_ONCE(!is_chained_work(wq)))
  22172. return;
  22173. +
  22174. + rcu_read_lock();
  22175. retry:
  22176. if (req_cpu == WORK_CPU_UNBOUND)
  22177. cpu = raw_smp_processor_id();
  22178. @@ -1366,10 +1395,8 @@
  22179. /* pwq determined, queue */
  22180. trace_workqueue_queue_work(req_cpu, pwq, work);
  22181. - if (WARN_ON(!list_empty(&work->entry))) {
  22182. - spin_unlock(&pwq->pool->lock);
  22183. - return;
  22184. - }
  22185. + if (WARN_ON(!list_empty(&work->entry)))
  22186. + goto out;
  22187. pwq->nr_in_flight[pwq->work_color]++;
  22188. work_flags = work_color_to_flags(pwq->work_color);
  22189. @@ -1385,7 +1412,9 @@
  22190. insert_work(pwq, work, worklist, work_flags);
  22191. +out:
  22192. spin_unlock(&pwq->pool->lock);
  22193. + rcu_read_unlock();
  22194. }
  22195. /**
  22196. @@ -1405,14 +1434,14 @@
  22197. bool ret = false;
  22198. unsigned long flags;
  22199. - local_irq_save(flags);
  22200. + local_lock_irqsave(pendingb_lock,flags);
  22201. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  22202. __queue_work(cpu, wq, work);
  22203. ret = true;
  22204. }
  22205. - local_irq_restore(flags);
  22206. + local_unlock_irqrestore(pendingb_lock, flags);
  22207. return ret;
  22208. }
  22209. EXPORT_SYMBOL(queue_work_on);
  22210. @@ -1479,14 +1508,14 @@
  22211. unsigned long flags;
  22212. /* read the comment in __queue_work() */
  22213. - local_irq_save(flags);
  22214. + local_lock_irqsave(pendingb_lock, flags);
  22215. if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) {
  22216. __queue_delayed_work(cpu, wq, dwork, delay);
  22217. ret = true;
  22218. }
  22219. - local_irq_restore(flags);
  22220. + local_unlock_irqrestore(pendingb_lock, flags);
  22221. return ret;
  22222. }
  22223. EXPORT_SYMBOL(queue_delayed_work_on);
  22224. @@ -1521,7 +1550,7 @@
  22225. if (likely(ret >= 0)) {
  22226. __queue_delayed_work(cpu, wq, dwork, delay);
  22227. - local_irq_restore(flags);
  22228. + local_unlock_irqrestore(pendingb_lock, flags);
  22229. }
  22230. /* -ENOENT from try_to_grab_pending() becomes %true */
  22231. @@ -1554,7 +1583,9 @@
  22232. worker->last_active = jiffies;
  22233. /* idle_list is LIFO */
  22234. + rt_lock_idle_list(pool);
  22235. list_add(&worker->entry, &pool->idle_list);
  22236. + rt_unlock_idle_list(pool);
  22237. if (too_many_workers(pool) && !timer_pending(&pool->idle_timer))
  22238. mod_timer(&pool->idle_timer, jiffies + IDLE_WORKER_TIMEOUT);
  22239. @@ -1587,7 +1618,9 @@
  22240. return;
  22241. worker_clr_flags(worker, WORKER_IDLE);
  22242. pool->nr_idle--;
  22243. + rt_lock_idle_list(pool);
  22244. list_del_init(&worker->entry);
  22245. + rt_unlock_idle_list(pool);
  22246. }
  22247. static struct worker *alloc_worker(int node)
  22248. @@ -1755,7 +1788,9 @@
  22249. pool->nr_workers--;
  22250. pool->nr_idle--;
  22251. + rt_lock_idle_list(pool);
  22252. list_del_init(&worker->entry);
  22253. + rt_unlock_idle_list(pool);
  22254. worker->flags |= WORKER_DIE;
  22255. wake_up_process(worker->task);
  22256. }
  22257. @@ -2672,14 +2707,14 @@
  22258. might_sleep();
  22259. - local_irq_disable();
  22260. + rcu_read_lock();
  22261. pool = get_work_pool(work);
  22262. if (!pool) {
  22263. - local_irq_enable();
  22264. + rcu_read_unlock();
  22265. return false;
  22266. }
  22267. - spin_lock(&pool->lock);
  22268. + spin_lock_irq(&pool->lock);
  22269. /* see the comment in try_to_grab_pending() with the same code */
  22270. pwq = get_work_pwq(work);
  22271. if (pwq) {
  22272. @@ -2706,10 +2741,11 @@
  22273. else
  22274. lock_map_acquire_read(&pwq->wq->lockdep_map);
  22275. lock_map_release(&pwq->wq->lockdep_map);
  22276. -
  22277. + rcu_read_unlock();
  22278. return true;
  22279. already_gone:
  22280. spin_unlock_irq(&pool->lock);
  22281. + rcu_read_unlock();
  22282. return false;
  22283. }
  22284. @@ -2796,7 +2832,7 @@
  22285. /* tell other tasks trying to grab @work to back off */
  22286. mark_work_canceling(work);
  22287. - local_irq_restore(flags);
  22288. + local_unlock_irqrestore(pendingb_lock, flags);
  22289. flush_work(work);
  22290. clear_work_data(work);
  22291. @@ -2851,10 +2887,10 @@
  22292. */
  22293. bool flush_delayed_work(struct delayed_work *dwork)
  22294. {
  22295. - local_irq_disable();
  22296. + local_lock_irq(pendingb_lock);
  22297. if (del_timer_sync(&dwork->timer))
  22298. __queue_work(dwork->cpu, dwork->wq, &dwork->work);
  22299. - local_irq_enable();
  22300. + local_unlock_irq(pendingb_lock);
  22301. return flush_work(&dwork->work);
  22302. }
  22303. EXPORT_SYMBOL(flush_delayed_work);
  22304. @@ -2889,7 +2925,7 @@
  22305. set_work_pool_and_clear_pending(&dwork->work,
  22306. get_work_pool_id(&dwork->work));
  22307. - local_irq_restore(flags);
  22308. + local_unlock_irqrestore(pendingb_lock, flags);
  22309. return ret;
  22310. }
  22311. EXPORT_SYMBOL(cancel_delayed_work);
  22312. @@ -3147,7 +3183,7 @@
  22313. * put_unbound_pool - put a worker_pool
  22314. * @pool: worker_pool to put
  22315. *
  22316. - * Put @pool. If its refcnt reaches zero, it gets destroyed in sched-RCU
  22317. + * Put @pool. If its refcnt reaches zero, it gets destroyed in RCU
  22318. * safe manner. get_unbound_pool() calls this function on its failure path
  22319. * and this function should be able to release pools which went through,
  22320. * successfully or not, init_worker_pool().
  22321. @@ -3201,8 +3237,8 @@
  22322. del_timer_sync(&pool->idle_timer);
  22323. del_timer_sync(&pool->mayday_timer);
  22324. - /* sched-RCU protected to allow dereferences from get_work_pool() */
  22325. - call_rcu_sched(&pool->rcu, rcu_free_pool);
  22326. + /* RCU protected to allow dereferences from get_work_pool() */
  22327. + call_rcu(&pool->rcu, rcu_free_pool);
  22328. }
  22329. /**
  22330. @@ -3307,14 +3343,14 @@
  22331. put_unbound_pool(pool);
  22332. mutex_unlock(&wq_pool_mutex);
  22333. - call_rcu_sched(&pwq->rcu, rcu_free_pwq);
  22334. + call_rcu(&pwq->rcu, rcu_free_pwq);
  22335. /*
  22336. * If we're the last pwq going away, @wq is already dead and no one
  22337. * is gonna access it anymore. Schedule RCU free.
  22338. */
  22339. if (is_last)
  22340. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  22341. + call_rcu(&wq->rcu, rcu_free_wq);
  22342. }
  22343. /**
  22344. @@ -3920,7 +3956,7 @@
  22345. * The base ref is never dropped on per-cpu pwqs. Directly
  22346. * schedule RCU free.
  22347. */
  22348. - call_rcu_sched(&wq->rcu, rcu_free_wq);
  22349. + call_rcu(&wq->rcu, rcu_free_wq);
  22350. } else {
  22351. /*
  22352. * We're the sole accessor of @wq at this point. Directly
  22353. @@ -4013,7 +4049,8 @@
  22354. struct pool_workqueue *pwq;
  22355. bool ret;
  22356. - rcu_read_lock_sched();
  22357. + rcu_read_lock();
  22358. + preempt_disable();
  22359. if (cpu == WORK_CPU_UNBOUND)
  22360. cpu = smp_processor_id();
  22361. @@ -4024,7 +4061,8 @@
  22362. pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu));
  22363. ret = !list_empty(&pwq->delayed_works);
  22364. - rcu_read_unlock_sched();
  22365. + preempt_enable();
  22366. + rcu_read_unlock();
  22367. return ret;
  22368. }
  22369. @@ -4050,15 +4088,15 @@
  22370. if (work_pending(work))
  22371. ret |= WORK_BUSY_PENDING;
  22372. - local_irq_save(flags);
  22373. + rcu_read_lock();
  22374. pool = get_work_pool(work);
  22375. if (pool) {
  22376. - spin_lock(&pool->lock);
  22377. + spin_lock_irqsave(&pool->lock, flags);
  22378. if (find_worker_executing_work(pool, work))
  22379. ret |= WORK_BUSY_RUNNING;
  22380. - spin_unlock(&pool->lock);
  22381. + spin_unlock_irqrestore(&pool->lock, flags);
  22382. }
  22383. - local_irq_restore(flags);
  22384. + rcu_read_unlock();
  22385. return ret;
  22386. }
  22387. @@ -4247,7 +4285,7 @@
  22388. unsigned long flags;
  22389. int pi;
  22390. - rcu_read_lock_sched();
  22391. + rcu_read_lock();
  22392. pr_info("Showing busy workqueues and worker pools:\n");
  22393. @@ -4298,7 +4336,7 @@
  22394. spin_unlock_irqrestore(&pool->lock, flags);
  22395. }
  22396. - rcu_read_unlock_sched();
  22397. + rcu_read_unlock();
  22398. }
  22399. /*
  22400. @@ -4648,16 +4686,16 @@
  22401. * nr_active is monotonically decreasing. It's safe
  22402. * to peek without lock.
  22403. */
  22404. - rcu_read_lock_sched();
  22405. + rcu_read_lock();
  22406. for_each_pwq(pwq, wq) {
  22407. WARN_ON_ONCE(pwq->nr_active < 0);
  22408. if (pwq->nr_active) {
  22409. busy = true;
  22410. - rcu_read_unlock_sched();
  22411. + rcu_read_unlock();
  22412. goto out_unlock;
  22413. }
  22414. }
  22415. - rcu_read_unlock_sched();
  22416. + rcu_read_unlock();
  22417. }
  22418. out_unlock:
  22419. mutex_unlock(&wq_pool_mutex);
  22420. @@ -4771,7 +4809,8 @@
  22421. const char *delim = "";
  22422. int node, written = 0;
  22423. - rcu_read_lock_sched();
  22424. + get_online_cpus();
  22425. + rcu_read_lock();
  22426. for_each_node(node) {
  22427. written += scnprintf(buf + written, PAGE_SIZE - written,
  22428. "%s%d:%d", delim, node,
  22429. @@ -4779,7 +4818,8 @@
  22430. delim = " ";
  22431. }
  22432. written += scnprintf(buf + written, PAGE_SIZE - written, "\n");
  22433. - rcu_read_unlock_sched();
  22434. + rcu_read_unlock();
  22435. + put_online_cpus();
  22436. return written;
  22437. }
  22438. diff -Nur linux-4.1.6.orig/kernel/workqueue_internal.h linux-4.1.6/kernel/workqueue_internal.h
  22439. --- linux-4.1.6.orig/kernel/workqueue_internal.h 2015-08-17 05:52:51.000000000 +0200
  22440. +++ linux-4.1.6/kernel/workqueue_internal.h 2015-09-08 23:49:08.425831903 +0200
  22441. @@ -43,6 +43,7 @@
  22442. unsigned long last_active; /* L: last active timestamp */
  22443. unsigned int flags; /* X: flags */
  22444. int id; /* I: worker id */
  22445. + int sleeping; /* None */
  22446. /*
  22447. * Opaque string set with work_set_desc(). Printed out with task
  22448. @@ -68,7 +69,7 @@
  22449. * Scheduler hooks for concurrency managed workqueue. Only to be used from
  22450. * sched/core.c and workqueue.c.
  22451. */
  22452. -void wq_worker_waking_up(struct task_struct *task, int cpu);
  22453. -struct task_struct *wq_worker_sleeping(struct task_struct *task, int cpu);
  22454. +void wq_worker_running(struct task_struct *task);
  22455. +void wq_worker_sleeping(struct task_struct *task);
  22456. #endif /* _KERNEL_WORKQUEUE_INTERNAL_H */
  22457. diff -Nur linux-4.1.6.orig/lib/debugobjects.c linux-4.1.6/lib/debugobjects.c
  22458. --- linux-4.1.6.orig/lib/debugobjects.c 2015-08-17 05:52:51.000000000 +0200
  22459. +++ linux-4.1.6/lib/debugobjects.c 2015-09-08 23:49:08.425831903 +0200
  22460. @@ -309,7 +309,10 @@
  22461. struct debug_obj *obj;
  22462. unsigned long flags;
  22463. - fill_pool();
  22464. +#ifdef CONFIG_PREEMPT_RT_FULL
  22465. + if (preempt_count() == 0 && !irqs_disabled())
  22466. +#endif
  22467. + fill_pool();
  22468. db = get_bucket((unsigned long) addr);
  22469. diff -Nur linux-4.1.6.orig/lib/dump_stack.c linux-4.1.6/lib/dump_stack.c
  22470. --- linux-4.1.6.orig/lib/dump_stack.c 2015-08-17 05:52:51.000000000 +0200
  22471. +++ linux-4.1.6/lib/dump_stack.c 2015-09-08 23:49:08.429831459 +0200
  22472. @@ -33,7 +33,7 @@
  22473. * Permit this cpu to perform nested stack dumps while serialising
  22474. * against other CPUs
  22475. */
  22476. - preempt_disable();
  22477. + migrate_disable();
  22478. retry:
  22479. cpu = smp_processor_id();
  22480. @@ -52,7 +52,7 @@
  22481. if (!was_locked)
  22482. atomic_set(&dump_lock, -1);
  22483. - preempt_enable();
  22484. + migrate_enable();
  22485. }
  22486. #else
  22487. asmlinkage __visible void dump_stack(void)
  22488. diff -Nur linux-4.1.6.orig/lib/idr.c linux-4.1.6/lib/idr.c
  22489. --- linux-4.1.6.orig/lib/idr.c 2015-08-17 05:52:51.000000000 +0200
  22490. +++ linux-4.1.6/lib/idr.c 2015-09-08 23:49:08.429831459 +0200
  22491. @@ -30,6 +30,7 @@
  22492. #include <linux/idr.h>
  22493. #include <linux/spinlock.h>
  22494. #include <linux/percpu.h>
  22495. +#include <linux/locallock.h>
  22496. #define MAX_IDR_SHIFT (sizeof(int) * 8 - 1)
  22497. #define MAX_IDR_BIT (1U << MAX_IDR_SHIFT)
  22498. @@ -366,6 +367,35 @@
  22499. idr_mark_full(pa, id);
  22500. }
  22501. +#ifdef CONFIG_PREEMPT_RT_FULL
  22502. +static DEFINE_LOCAL_IRQ_LOCK(idr_lock);
  22503. +
  22504. +static inline void idr_preload_lock(void)
  22505. +{
  22506. + local_lock(idr_lock);
  22507. +}
  22508. +
  22509. +static inline void idr_preload_unlock(void)
  22510. +{
  22511. + local_unlock(idr_lock);
  22512. +}
  22513. +
  22514. +void idr_preload_end(void)
  22515. +{
  22516. + idr_preload_unlock();
  22517. +}
  22518. +EXPORT_SYMBOL(idr_preload_end);
  22519. +#else
  22520. +static inline void idr_preload_lock(void)
  22521. +{
  22522. + preempt_disable();
  22523. +}
  22524. +
  22525. +static inline void idr_preload_unlock(void)
  22526. +{
  22527. + preempt_enable();
  22528. +}
  22529. +#endif
  22530. /**
  22531. * idr_preload - preload for idr_alloc()
  22532. @@ -401,7 +431,7 @@
  22533. WARN_ON_ONCE(in_interrupt());
  22534. might_sleep_if(gfp_mask & __GFP_WAIT);
  22535. - preempt_disable();
  22536. + idr_preload_lock();
  22537. /*
  22538. * idr_alloc() is likely to succeed w/o full idr_layer buffer and
  22539. @@ -413,9 +443,9 @@
  22540. while (__this_cpu_read(idr_preload_cnt) < MAX_IDR_FREE) {
  22541. struct idr_layer *new;
  22542. - preempt_enable();
  22543. + idr_preload_unlock();
  22544. new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
  22545. - preempt_disable();
  22546. + idr_preload_lock();
  22547. if (!new)
  22548. break;
  22549. diff -Nur linux-4.1.6.orig/lib/Kconfig linux-4.1.6/lib/Kconfig
  22550. --- linux-4.1.6.orig/lib/Kconfig 2015-08-17 05:52:51.000000000 +0200
  22551. +++ linux-4.1.6/lib/Kconfig 2015-09-08 23:49:08.425831903 +0200
  22552. @@ -391,6 +391,7 @@
  22553. config CPUMASK_OFFSTACK
  22554. bool "Force CPU masks off stack" if DEBUG_PER_CPU_MAPS
  22555. + depends on !PREEMPT_RT_FULL
  22556. help
  22557. Use dynamic allocation for cpumask_var_t, instead of putting
  22558. them on the stack. This is a bit more expensive, but avoids
  22559. diff -Nur linux-4.1.6.orig/lib/locking-selftest.c linux-4.1.6/lib/locking-selftest.c
  22560. --- linux-4.1.6.orig/lib/locking-selftest.c 2015-08-17 05:52:51.000000000 +0200
  22561. +++ linux-4.1.6/lib/locking-selftest.c 2015-09-08 23:49:08.429831459 +0200
  22562. @@ -590,6 +590,8 @@
  22563. #include "locking-selftest-spin-hardirq.h"
  22564. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
  22565. +#ifndef CONFIG_PREEMPT_RT_FULL
  22566. +
  22567. #include "locking-selftest-rlock-hardirq.h"
  22568. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
  22569. @@ -605,9 +607,12 @@
  22570. #include "locking-selftest-wlock-softirq.h"
  22571. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
  22572. +#endif
  22573. +
  22574. #undef E1
  22575. #undef E2
  22576. +#ifndef CONFIG_PREEMPT_RT_FULL
  22577. /*
  22578. * Enabling hardirqs with a softirq-safe lock held:
  22579. */
  22580. @@ -640,6 +645,8 @@
  22581. #undef E1
  22582. #undef E2
  22583. +#endif
  22584. +
  22585. /*
  22586. * Enabling irqs with an irq-safe lock held:
  22587. */
  22588. @@ -663,6 +670,8 @@
  22589. #include "locking-selftest-spin-hardirq.h"
  22590. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
  22591. +#ifndef CONFIG_PREEMPT_RT_FULL
  22592. +
  22593. #include "locking-selftest-rlock-hardirq.h"
  22594. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
  22595. @@ -678,6 +687,8 @@
  22596. #include "locking-selftest-wlock-softirq.h"
  22597. GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
  22598. +#endif
  22599. +
  22600. #undef E1
  22601. #undef E2
  22602. @@ -709,6 +720,8 @@
  22603. #include "locking-selftest-spin-hardirq.h"
  22604. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
  22605. +#ifndef CONFIG_PREEMPT_RT_FULL
  22606. +
  22607. #include "locking-selftest-rlock-hardirq.h"
  22608. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
  22609. @@ -724,6 +737,8 @@
  22610. #include "locking-selftest-wlock-softirq.h"
  22611. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
  22612. +#endif
  22613. +
  22614. #undef E1
  22615. #undef E2
  22616. #undef E3
  22617. @@ -757,6 +772,8 @@
  22618. #include "locking-selftest-spin-hardirq.h"
  22619. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
  22620. +#ifndef CONFIG_PREEMPT_RT_FULL
  22621. +
  22622. #include "locking-selftest-rlock-hardirq.h"
  22623. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
  22624. @@ -772,10 +789,14 @@
  22625. #include "locking-selftest-wlock-softirq.h"
  22626. GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
  22627. +#endif
  22628. +
  22629. #undef E1
  22630. #undef E2
  22631. #undef E3
  22632. +#ifndef CONFIG_PREEMPT_RT_FULL
  22633. +
  22634. /*
  22635. * read-lock / write-lock irq inversion.
  22636. *
  22637. @@ -838,6 +859,10 @@
  22638. #undef E2
  22639. #undef E3
  22640. +#endif
  22641. +
  22642. +#ifndef CONFIG_PREEMPT_RT_FULL
  22643. +
  22644. /*
  22645. * read-lock / write-lock recursion that is actually safe.
  22646. */
  22647. @@ -876,6 +901,8 @@
  22648. #undef E2
  22649. #undef E3
  22650. +#endif
  22651. +
  22652. /*
  22653. * read-lock / write-lock recursion that is unsafe.
  22654. */
  22655. @@ -1858,6 +1885,7 @@
  22656. printk(" --------------------------------------------------------------------------\n");
  22657. +#ifndef CONFIG_PREEMPT_RT_FULL
  22658. /*
  22659. * irq-context testcases:
  22660. */
  22661. @@ -1870,6 +1898,28 @@
  22662. DO_TESTCASE_6x2("irq read-recursion", irq_read_recursion);
  22663. // DO_TESTCASE_6x2B("irq read-recursion #2", irq_read_recursion2);
  22664. +#else
  22665. + /* On -rt, we only do hardirq context test for raw spinlock */
  22666. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 12);
  22667. + DO_TESTCASE_1B("hard-irqs-on + irq-safe-A", irqsafe1_hard_spin, 21);
  22668. +
  22669. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 12);
  22670. + DO_TESTCASE_1B("hard-safe-A + irqs-on", irqsafe2B_hard_spin, 21);
  22671. +
  22672. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 123);
  22673. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 132);
  22674. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 213);
  22675. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 231);
  22676. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 312);
  22677. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #1", irqsafe3_hard_spin, 321);
  22678. +
  22679. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 123);
  22680. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 132);
  22681. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 213);
  22682. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 231);
  22683. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 312);
  22684. + DO_TESTCASE_1B("hard-safe-A + unsafe-B #2", irqsafe4_hard_spin, 321);
  22685. +#endif
  22686. ww_tests();
  22687. diff -Nur linux-4.1.6.orig/lib/percpu_ida.c linux-4.1.6/lib/percpu_ida.c
  22688. --- linux-4.1.6.orig/lib/percpu_ida.c 2015-08-17 05:52:51.000000000 +0200
  22689. +++ linux-4.1.6/lib/percpu_ida.c 2015-09-08 23:49:08.433831016 +0200
  22690. @@ -26,6 +26,9 @@
  22691. #include <linux/string.h>
  22692. #include <linux/spinlock.h>
  22693. #include <linux/percpu_ida.h>
  22694. +#include <linux/locallock.h>
  22695. +
  22696. +static DEFINE_LOCAL_IRQ_LOCK(irq_off_lock);
  22697. struct percpu_ida_cpu {
  22698. /*
  22699. @@ -148,13 +151,13 @@
  22700. unsigned long flags;
  22701. int tag;
  22702. - local_irq_save(flags);
  22703. + local_lock_irqsave(irq_off_lock, flags);
  22704. tags = this_cpu_ptr(pool->tag_cpu);
  22705. /* Fastpath */
  22706. tag = alloc_local_tag(tags);
  22707. if (likely(tag >= 0)) {
  22708. - local_irq_restore(flags);
  22709. + local_unlock_irqrestore(irq_off_lock, flags);
  22710. return tag;
  22711. }
  22712. @@ -173,6 +176,7 @@
  22713. if (!tags->nr_free)
  22714. alloc_global_tags(pool, tags);
  22715. +
  22716. if (!tags->nr_free)
  22717. steal_tags(pool, tags);
  22718. @@ -184,7 +188,7 @@
  22719. }
  22720. spin_unlock(&pool->lock);
  22721. - local_irq_restore(flags);
  22722. + local_unlock_irqrestore(irq_off_lock, flags);
  22723. if (tag >= 0 || state == TASK_RUNNING)
  22724. break;
  22725. @@ -196,7 +200,7 @@
  22726. schedule();
  22727. - local_irq_save(flags);
  22728. + local_lock_irqsave(irq_off_lock, flags);
  22729. tags = this_cpu_ptr(pool->tag_cpu);
  22730. }
  22731. if (state != TASK_RUNNING)
  22732. @@ -221,7 +225,7 @@
  22733. BUG_ON(tag >= pool->nr_tags);
  22734. - local_irq_save(flags);
  22735. + local_lock_irqsave(irq_off_lock, flags);
  22736. tags = this_cpu_ptr(pool->tag_cpu);
  22737. spin_lock(&tags->lock);
  22738. @@ -253,7 +257,7 @@
  22739. spin_unlock(&pool->lock);
  22740. }
  22741. - local_irq_restore(flags);
  22742. + local_unlock_irqrestore(irq_off_lock, flags);
  22743. }
  22744. EXPORT_SYMBOL_GPL(percpu_ida_free);
  22745. @@ -345,7 +349,7 @@
  22746. struct percpu_ida_cpu *remote;
  22747. unsigned cpu, i, err = 0;
  22748. - local_irq_save(flags);
  22749. + local_lock_irqsave(irq_off_lock, flags);
  22750. for_each_possible_cpu(cpu) {
  22751. remote = per_cpu_ptr(pool->tag_cpu, cpu);
  22752. spin_lock(&remote->lock);
  22753. @@ -367,7 +371,7 @@
  22754. }
  22755. spin_unlock(&pool->lock);
  22756. out:
  22757. - local_irq_restore(flags);
  22758. + local_unlock_irqrestore(irq_off_lock, flags);
  22759. return err;
  22760. }
  22761. EXPORT_SYMBOL_GPL(percpu_ida_for_each_free);
  22762. diff -Nur linux-4.1.6.orig/lib/radix-tree.c linux-4.1.6/lib/radix-tree.c
  22763. --- linux-4.1.6.orig/lib/radix-tree.c 2015-08-17 05:52:51.000000000 +0200
  22764. +++ linux-4.1.6/lib/radix-tree.c 2015-09-08 23:49:08.433831016 +0200
  22765. @@ -195,12 +195,13 @@
  22766. * succeed in getting a node here (and never reach
  22767. * kmem_cache_alloc)
  22768. */
  22769. - rtp = this_cpu_ptr(&radix_tree_preloads);
  22770. + rtp = &get_cpu_var(radix_tree_preloads);
  22771. if (rtp->nr) {
  22772. ret = rtp->nodes[rtp->nr - 1];
  22773. rtp->nodes[rtp->nr - 1] = NULL;
  22774. rtp->nr--;
  22775. }
  22776. + put_cpu_var(radix_tree_preloads);
  22777. /*
  22778. * Update the allocation stack trace as this is more useful
  22779. * for debugging.
  22780. @@ -240,6 +241,7 @@
  22781. call_rcu(&node->rcu_head, radix_tree_node_rcu_free);
  22782. }
  22783. +#ifndef CONFIG_PREEMPT_RT_FULL
  22784. /*
  22785. * Load up this CPU's radix_tree_node buffer with sufficient objects to
  22786. * ensure that the addition of a single element in the tree cannot fail. On
  22787. @@ -305,6 +307,7 @@
  22788. return 0;
  22789. }
  22790. EXPORT_SYMBOL(radix_tree_maybe_preload);
  22791. +#endif
  22792. /*
  22793. * Return the maximum key which can be store into a
  22794. diff -Nur linux-4.1.6.orig/lib/scatterlist.c linux-4.1.6/lib/scatterlist.c
  22795. --- linux-4.1.6.orig/lib/scatterlist.c 2015-08-17 05:52:51.000000000 +0200
  22796. +++ linux-4.1.6/lib/scatterlist.c 2015-09-08 23:49:08.433831016 +0200
  22797. @@ -592,7 +592,7 @@
  22798. flush_kernel_dcache_page(miter->page);
  22799. if (miter->__flags & SG_MITER_ATOMIC) {
  22800. - WARN_ON_ONCE(preemptible());
  22801. + WARN_ON_ONCE(!pagefault_disabled());
  22802. kunmap_atomic(miter->addr);
  22803. } else
  22804. kunmap(miter->page);
  22805. @@ -637,7 +637,7 @@
  22806. if (!sg_miter_skip(&miter, skip))
  22807. return false;
  22808. - local_irq_save(flags);
  22809. + local_irq_save_nort(flags);
  22810. while (sg_miter_next(&miter) && offset < buflen) {
  22811. unsigned int len;
  22812. @@ -654,7 +654,7 @@
  22813. sg_miter_stop(&miter);
  22814. - local_irq_restore(flags);
  22815. + local_irq_restore_nort(flags);
  22816. return offset;
  22817. }
  22818. diff -Nur linux-4.1.6.orig/lib/smp_processor_id.c linux-4.1.6/lib/smp_processor_id.c
  22819. --- linux-4.1.6.orig/lib/smp_processor_id.c 2015-08-17 05:52:51.000000000 +0200
  22820. +++ linux-4.1.6/lib/smp_processor_id.c 2015-09-08 23:49:08.433831016 +0200
  22821. @@ -39,8 +39,9 @@
  22822. if (!printk_ratelimit())
  22823. goto out_enable;
  22824. - printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x] code: %s/%d\n",
  22825. - what1, what2, preempt_count() - 1, current->comm, current->pid);
  22826. + printk(KERN_ERR "BUG: using %s%s() in preemptible [%08x %08x] code: %s/%d\n",
  22827. + what1, what2, preempt_count() - 1, __migrate_disabled(current),
  22828. + current->comm, current->pid);
  22829. print_symbol("caller is %s\n", (long)__builtin_return_address(0));
  22830. dump_stack();
  22831. diff -Nur linux-4.1.6.orig/lib/strnlen_user.c linux-4.1.6/lib/strnlen_user.c
  22832. --- linux-4.1.6.orig/lib/strnlen_user.c 2015-08-17 05:52:51.000000000 +0200
  22833. +++ linux-4.1.6/lib/strnlen_user.c 2015-09-08 23:49:08.433831016 +0200
  22834. @@ -85,7 +85,8 @@
  22835. * @str: The string to measure.
  22836. * @count: Maximum count (including NUL character)
  22837. *
  22838. - * Context: User context only. This function may sleep.
  22839. + * Context: User context only. This function may sleep if pagefaults are
  22840. + * enabled.
  22841. *
  22842. * Get the size of a NUL-terminated string in user space.
  22843. *
  22844. @@ -121,7 +122,8 @@
  22845. * strlen_user: - Get the size of a user string INCLUDING final NUL.
  22846. * @str: The string to measure.
  22847. *
  22848. - * Context: User context only. This function may sleep.
  22849. + * Context: User context only. This function may sleep if pagefaults are
  22850. + * enabled.
  22851. *
  22852. * Get the size of a NUL-terminated string in user space.
  22853. *
  22854. diff -Nur linux-4.1.6.orig/mm/compaction.c linux-4.1.6/mm/compaction.c
  22855. --- linux-4.1.6.orig/mm/compaction.c 2015-08-17 05:52:51.000000000 +0200
  22856. +++ linux-4.1.6/mm/compaction.c 2015-09-08 23:49:08.437830574 +0200
  22857. @@ -1406,10 +1406,12 @@
  22858. cc->migrate_pfn & ~((1UL << cc->order) - 1);
  22859. if (last_migrated_pfn < current_block_start) {
  22860. - cpu = get_cpu();
  22861. + cpu = get_cpu_light();
  22862. + local_lock_irq(swapvec_lock);
  22863. lru_add_drain_cpu(cpu);
  22864. + local_unlock_irq(swapvec_lock);
  22865. drain_local_pages(zone);
  22866. - put_cpu();
  22867. + put_cpu_light();
  22868. /* No more flushing until we migrate again */
  22869. last_migrated_pfn = 0;
  22870. }
  22871. diff -Nur linux-4.1.6.orig/mm/filemap.c linux-4.1.6/mm/filemap.c
  22872. --- linux-4.1.6.orig/mm/filemap.c 2015-08-17 05:52:51.000000000 +0200
  22873. +++ linux-4.1.6/mm/filemap.c 2015-09-08 23:49:08.437830574 +0200
  22874. @@ -167,7 +167,9 @@
  22875. if (!workingset_node_pages(node) &&
  22876. list_empty(&node->private_list)) {
  22877. node->private_data = mapping;
  22878. - list_lru_add(&workingset_shadow_nodes, &node->private_list);
  22879. + local_lock(workingset_shadow_lock);
  22880. + list_lru_add(&__workingset_shadow_nodes, &node->private_list);
  22881. + local_unlock(workingset_shadow_lock);
  22882. }
  22883. }
  22884. @@ -533,9 +535,12 @@
  22885. * node->private_list is protected by
  22886. * mapping->tree_lock.
  22887. */
  22888. - if (!list_empty(&node->private_list))
  22889. - list_lru_del(&workingset_shadow_nodes,
  22890. + if (!list_empty(&node->private_list)) {
  22891. + local_lock(workingset_shadow_lock);
  22892. + list_lru_del(&__workingset_shadow_nodes,
  22893. &node->private_list);
  22894. + local_unlock(workingset_shadow_lock);
  22895. + }
  22896. }
  22897. return 0;
  22898. }
  22899. diff -Nur linux-4.1.6.orig/mm/highmem.c linux-4.1.6/mm/highmem.c
  22900. --- linux-4.1.6.orig/mm/highmem.c 2015-08-17 05:52:51.000000000 +0200
  22901. +++ linux-4.1.6/mm/highmem.c 2015-09-08 23:49:08.437830574 +0200
  22902. @@ -29,10 +29,11 @@
  22903. #include <linux/kgdb.h>
  22904. #include <asm/tlbflush.h>
  22905. -
  22906. +#ifndef CONFIG_PREEMPT_RT_FULL
  22907. #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
  22908. DEFINE_PER_CPU(int, __kmap_atomic_idx);
  22909. #endif
  22910. +#endif
  22911. /*
  22912. * Virtual_count is not a pure "count".
  22913. @@ -107,8 +108,9 @@
  22914. unsigned long totalhigh_pages __read_mostly;
  22915. EXPORT_SYMBOL(totalhigh_pages);
  22916. -
  22917. +#ifndef CONFIG_PREEMPT_RT_FULL
  22918. EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
  22919. +#endif
  22920. unsigned int nr_free_highpages (void)
  22921. {
  22922. diff -Nur linux-4.1.6.orig/mm/Kconfig linux-4.1.6/mm/Kconfig
  22923. --- linux-4.1.6.orig/mm/Kconfig 2015-08-17 05:52:51.000000000 +0200
  22924. +++ linux-4.1.6/mm/Kconfig 2015-09-08 23:49:08.437830574 +0200
  22925. @@ -409,7 +409,7 @@
  22926. config TRANSPARENT_HUGEPAGE
  22927. bool "Transparent Hugepage Support"
  22928. - depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE
  22929. + depends on HAVE_ARCH_TRANSPARENT_HUGEPAGE && !PREEMPT_RT_FULL
  22930. select COMPACTION
  22931. help
  22932. Transparent Hugepages allows the kernel to use huge pages and
  22933. diff -Nur linux-4.1.6.orig/mm/memcontrol.c linux-4.1.6/mm/memcontrol.c
  22934. --- linux-4.1.6.orig/mm/memcontrol.c 2015-08-17 05:52:51.000000000 +0200
  22935. +++ linux-4.1.6/mm/memcontrol.c 2015-09-08 23:49:08.437830574 +0200
  22936. @@ -66,6 +66,8 @@
  22937. #include <net/sock.h>
  22938. #include <net/ip.h>
  22939. #include <net/tcp_memcontrol.h>
  22940. +#include <linux/locallock.h>
  22941. +
  22942. #include "slab.h"
  22943. #include <asm/uaccess.h>
  22944. @@ -85,6 +87,7 @@
  22945. #define do_swap_account 0
  22946. #endif
  22947. +static DEFINE_LOCAL_IRQ_LOCK(event_lock);
  22948. static const char * const mem_cgroup_stat_names[] = {
  22949. "cache",
  22950. "rss",
  22951. @@ -2124,14 +2127,17 @@
  22952. */
  22953. static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
  22954. {
  22955. - struct memcg_stock_pcp *stock = &get_cpu_var(memcg_stock);
  22956. + struct memcg_stock_pcp *stock;
  22957. + int cpu = get_cpu_light();
  22958. +
  22959. + stock = &per_cpu(memcg_stock, cpu);
  22960. if (stock->cached != memcg) { /* reset if necessary */
  22961. drain_stock(stock);
  22962. stock->cached = memcg;
  22963. }
  22964. stock->nr_pages += nr_pages;
  22965. - put_cpu_var(memcg_stock);
  22966. + put_cpu_light();
  22967. }
  22968. /*
  22969. @@ -2147,7 +2153,7 @@
  22970. return;
  22971. /* Notify other cpus that system-wide "drain" is running */
  22972. get_online_cpus();
  22973. - curcpu = get_cpu();
  22974. + curcpu = get_cpu_light();
  22975. for_each_online_cpu(cpu) {
  22976. struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
  22977. struct mem_cgroup *memcg;
  22978. @@ -2164,7 +2170,7 @@
  22979. schedule_work_on(cpu, &stock->work);
  22980. }
  22981. }
  22982. - put_cpu();
  22983. + put_cpu_light();
  22984. put_online_cpus();
  22985. mutex_unlock(&percpu_charge_mutex);
  22986. }
  22987. @@ -4801,12 +4807,12 @@
  22988. ret = 0;
  22989. - local_irq_disable();
  22990. + local_lock_irq(event_lock);
  22991. mem_cgroup_charge_statistics(to, page, nr_pages);
  22992. memcg_check_events(to, page);
  22993. mem_cgroup_charge_statistics(from, page, -nr_pages);
  22994. memcg_check_events(from, page);
  22995. - local_irq_enable();
  22996. + local_unlock_irq(event_lock);
  22997. out_unlock:
  22998. unlock_page(page);
  22999. out:
  23000. @@ -5543,10 +5549,10 @@
  23001. VM_BUG_ON_PAGE(!PageTransHuge(page), page);
  23002. }
  23003. - local_irq_disable();
  23004. + local_lock_irq(event_lock);
  23005. mem_cgroup_charge_statistics(memcg, page, nr_pages);
  23006. memcg_check_events(memcg, page);
  23007. - local_irq_enable();
  23008. + local_unlock_irq(event_lock);
  23009. if (do_swap_account && PageSwapCache(page)) {
  23010. swp_entry_t entry = { .val = page_private(page) };
  23011. @@ -5602,14 +5608,14 @@
  23012. memcg_oom_recover(memcg);
  23013. }
  23014. - local_irq_save(flags);
  23015. + local_lock_irqsave(event_lock, flags);
  23016. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS], nr_anon);
  23017. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_CACHE], nr_file);
  23018. __this_cpu_sub(memcg->stat->count[MEM_CGROUP_STAT_RSS_HUGE], nr_huge);
  23019. __this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT], pgpgout);
  23020. __this_cpu_add(memcg->stat->nr_page_events, nr_pages);
  23021. memcg_check_events(memcg, dummy_page);
  23022. - local_irq_restore(flags);
  23023. + local_unlock_irqrestore(event_lock, flags);
  23024. if (!mem_cgroup_is_root(memcg))
  23025. css_put_many(&memcg->css, nr_pages);
  23026. @@ -5813,6 +5819,7 @@
  23027. {
  23028. struct mem_cgroup *memcg;
  23029. unsigned short oldid;
  23030. + unsigned long flags;
  23031. VM_BUG_ON_PAGE(PageLRU(page), page);
  23032. VM_BUG_ON_PAGE(page_count(page), page);
  23033. @@ -5835,9 +5842,11 @@
  23034. if (!mem_cgroup_is_root(memcg))
  23035. page_counter_uncharge(&memcg->memory, 1);
  23036. + local_lock_irqsave(event_lock, flags);
  23037. /* Caller disabled preemption with mapping->tree_lock */
  23038. mem_cgroup_charge_statistics(memcg, page, -1);
  23039. memcg_check_events(memcg, page);
  23040. + local_unlock_irqrestore(event_lock, flags);
  23041. }
  23042. /**
  23043. diff -Nur linux-4.1.6.orig/mm/memory.c linux-4.1.6/mm/memory.c
  23044. --- linux-4.1.6.orig/mm/memory.c 2015-08-17 05:52:51.000000000 +0200
  23045. +++ linux-4.1.6/mm/memory.c 2015-09-08 23:49:08.437830574 +0200
  23046. @@ -3743,7 +3743,7 @@
  23047. }
  23048. #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)
  23049. -void might_fault(void)
  23050. +void __might_fault(const char *file, int line)
  23051. {
  23052. /*
  23053. * Some code (nfs/sunrpc) uses socket ops on kernel memory while
  23054. @@ -3753,21 +3753,15 @@
  23055. */
  23056. if (segment_eq(get_fs(), KERNEL_DS))
  23057. return;
  23058. -
  23059. - /*
  23060. - * it would be nicer only to annotate paths which are not under
  23061. - * pagefault_disable, however that requires a larger audit and
  23062. - * providing helpers like get_user_atomic.
  23063. - */
  23064. - if (in_atomic())
  23065. + if (pagefault_disabled())
  23066. return;
  23067. -
  23068. - __might_sleep(__FILE__, __LINE__, 0);
  23069. -
  23070. + __might_sleep(file, line, 0);
  23071. +#if defined(CONFIG_DEBUG_ATOMIC_SLEEP)
  23072. if (current->mm)
  23073. might_lock_read(&current->mm->mmap_sem);
  23074. +#endif
  23075. }
  23076. -EXPORT_SYMBOL(might_fault);
  23077. +EXPORT_SYMBOL(__might_fault);
  23078. #endif
  23079. #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
  23080. diff -Nur linux-4.1.6.orig/mm/mmu_context.c linux-4.1.6/mm/mmu_context.c
  23081. --- linux-4.1.6.orig/mm/mmu_context.c 2015-08-17 05:52:51.000000000 +0200
  23082. +++ linux-4.1.6/mm/mmu_context.c 2015-09-08 23:49:08.437830574 +0200
  23083. @@ -23,6 +23,7 @@
  23084. struct task_struct *tsk = current;
  23085. task_lock(tsk);
  23086. + preempt_disable_rt();
  23087. active_mm = tsk->active_mm;
  23088. if (active_mm != mm) {
  23089. atomic_inc(&mm->mm_count);
  23090. @@ -30,6 +31,7 @@
  23091. }
  23092. tsk->mm = mm;
  23093. switch_mm(active_mm, mm, tsk);
  23094. + preempt_enable_rt();
  23095. task_unlock(tsk);
  23096. #ifdef finish_arch_post_lock_switch
  23097. finish_arch_post_lock_switch();
  23098. diff -Nur linux-4.1.6.orig/mm/page_alloc.c linux-4.1.6/mm/page_alloc.c
  23099. --- linux-4.1.6.orig/mm/page_alloc.c 2015-08-17 05:52:51.000000000 +0200
  23100. +++ linux-4.1.6/mm/page_alloc.c 2015-09-08 23:49:08.437830574 +0200
  23101. @@ -60,6 +60,7 @@
  23102. #include <linux/page_ext.h>
  23103. #include <linux/hugetlb.h>
  23104. #include <linux/sched/rt.h>
  23105. +#include <linux/locallock.h>
  23106. #include <linux/page_owner.h>
  23107. #include <asm/sections.h>
  23108. @@ -233,6 +234,18 @@
  23109. EXPORT_SYMBOL(nr_online_nodes);
  23110. #endif
  23111. +static DEFINE_LOCAL_IRQ_LOCK(pa_lock);
  23112. +
  23113. +#ifdef CONFIG_PREEMPT_RT_BASE
  23114. +# define cpu_lock_irqsave(cpu, flags) \
  23115. + local_lock_irqsave_on(pa_lock, flags, cpu)
  23116. +# define cpu_unlock_irqrestore(cpu, flags) \
  23117. + local_unlock_irqrestore_on(pa_lock, flags, cpu)
  23118. +#else
  23119. +# define cpu_lock_irqsave(cpu, flags) local_irq_save(flags)
  23120. +# define cpu_unlock_irqrestore(cpu, flags) local_irq_restore(flags)
  23121. +#endif
  23122. +
  23123. int page_group_by_mobility_disabled __read_mostly;
  23124. void set_pageblock_migratetype(struct page *page, int migratetype)
  23125. @@ -681,7 +694,7 @@
  23126. }
  23127. /*
  23128. - * Frees a number of pages from the PCP lists
  23129. + * Frees a number of pages which have been collected from the pcp lists.
  23130. * Assumes all pages on list are in same zone, and of same order.
  23131. * count is the number of pages to free.
  23132. *
  23133. @@ -692,18 +705,51 @@
  23134. * pinned" detection logic.
  23135. */
  23136. static void free_pcppages_bulk(struct zone *zone, int count,
  23137. - struct per_cpu_pages *pcp)
  23138. + struct list_head *list)
  23139. {
  23140. - int migratetype = 0;
  23141. - int batch_free = 0;
  23142. int to_free = count;
  23143. unsigned long nr_scanned;
  23144. + unsigned long flags;
  23145. +
  23146. + spin_lock_irqsave(&zone->lock, flags);
  23147. - spin_lock(&zone->lock);
  23148. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  23149. if (nr_scanned)
  23150. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  23151. + while (!list_empty(list)) {
  23152. + struct page *page = list_first_entry(list, struct page, lru);
  23153. + int mt; /* migratetype of the to-be-freed page */
  23154. +
  23155. + /* must delete as __free_one_page list manipulates */
  23156. + list_del(&page->lru);
  23157. +
  23158. + mt = get_freepage_migratetype(page);
  23159. + if (unlikely(has_isolate_pageblock(zone)))
  23160. + mt = get_pageblock_migratetype(page);
  23161. +
  23162. + /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
  23163. + __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  23164. + trace_mm_page_pcpu_drain(page, 0, mt);
  23165. + to_free--;
  23166. + }
  23167. + WARN_ON(to_free != 0);
  23168. + spin_unlock_irqrestore(&zone->lock, flags);
  23169. +}
  23170. +
  23171. +/*
  23172. + * Moves a number of pages from the PCP lists to free list which
  23173. + * is freed outside of the locked region.
  23174. + *
  23175. + * Assumes all pages on list are in same zone, and of same order.
  23176. + * count is the number of pages to free.
  23177. + */
  23178. +static void isolate_pcp_pages(int to_free, struct per_cpu_pages *src,
  23179. + struct list_head *dst)
  23180. +{
  23181. + int migratetype = 0;
  23182. + int batch_free = 0;
  23183. +
  23184. while (to_free) {
  23185. struct page *page;
  23186. struct list_head *list;
  23187. @@ -719,7 +765,7 @@
  23188. batch_free++;
  23189. if (++migratetype == MIGRATE_PCPTYPES)
  23190. migratetype = 0;
  23191. - list = &pcp->lists[migratetype];
  23192. + list = &src->lists[migratetype];
  23193. } while (list_empty(list));
  23194. /* This is the only non-empty list. Free them all. */
  23195. @@ -727,21 +773,11 @@
  23196. batch_free = to_free;
  23197. do {
  23198. - int mt; /* migratetype of the to-be-freed page */
  23199. -
  23200. - page = list_entry(list->prev, struct page, lru);
  23201. - /* must delete as __free_one_page list manipulates */
  23202. + page = list_last_entry(list, struct page, lru);
  23203. list_del(&page->lru);
  23204. - mt = get_freepage_migratetype(page);
  23205. - if (unlikely(has_isolate_pageblock(zone)))
  23206. - mt = get_pageblock_migratetype(page);
  23207. -
  23208. - /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
  23209. - __free_one_page(page, page_to_pfn(page), zone, 0, mt);
  23210. - trace_mm_page_pcpu_drain(page, 0, mt);
  23211. + list_add(&page->lru, dst);
  23212. } while (--to_free && --batch_free && !list_empty(list));
  23213. }
  23214. - spin_unlock(&zone->lock);
  23215. }
  23216. static void free_one_page(struct zone *zone,
  23217. @@ -750,7 +786,9 @@
  23218. int migratetype)
  23219. {
  23220. unsigned long nr_scanned;
  23221. - spin_lock(&zone->lock);
  23222. + unsigned long flags;
  23223. +
  23224. + spin_lock_irqsave(&zone->lock, flags);
  23225. nr_scanned = zone_page_state(zone, NR_PAGES_SCANNED);
  23226. if (nr_scanned)
  23227. __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
  23228. @@ -760,7 +798,7 @@
  23229. migratetype = get_pfnblock_migratetype(page, pfn);
  23230. }
  23231. __free_one_page(page, pfn, zone, order, migratetype);
  23232. - spin_unlock(&zone->lock);
  23233. + spin_unlock_irqrestore(&zone->lock, flags);
  23234. }
  23235. static int free_tail_pages_check(struct page *head_page, struct page *page)
  23236. @@ -825,11 +863,11 @@
  23237. return;
  23238. migratetype = get_pfnblock_migratetype(page, pfn);
  23239. - local_irq_save(flags);
  23240. + local_lock_irqsave(pa_lock, flags);
  23241. __count_vm_events(PGFREE, 1 << order);
  23242. set_freepage_migratetype(page, migratetype);
  23243. free_one_page(page_zone(page), page, pfn, order, migratetype);
  23244. - local_irq_restore(flags);
  23245. + local_unlock_irqrestore(pa_lock, flags);
  23246. }
  23247. void __init __free_pages_bootmem(struct page *page, unsigned int order)
  23248. @@ -1368,16 +1406,18 @@
  23249. void drain_zone_pages(struct zone *zone, struct per_cpu_pages *pcp)
  23250. {
  23251. unsigned long flags;
  23252. + LIST_HEAD(dst);
  23253. int to_drain, batch;
  23254. - local_irq_save(flags);
  23255. + local_lock_irqsave(pa_lock, flags);
  23256. batch = READ_ONCE(pcp->batch);
  23257. to_drain = min(pcp->count, batch);
  23258. if (to_drain > 0) {
  23259. - free_pcppages_bulk(zone, to_drain, pcp);
  23260. + isolate_pcp_pages(to_drain, pcp, &dst);
  23261. pcp->count -= to_drain;
  23262. }
  23263. - local_irq_restore(flags);
  23264. + local_unlock_irqrestore(pa_lock, flags);
  23265. + free_pcppages_bulk(zone, to_drain, &dst);
  23266. }
  23267. #endif
  23268. @@ -1393,16 +1433,21 @@
  23269. unsigned long flags;
  23270. struct per_cpu_pageset *pset;
  23271. struct per_cpu_pages *pcp;
  23272. + LIST_HEAD(dst);
  23273. + int count;
  23274. - local_irq_save(flags);
  23275. + cpu_lock_irqsave(cpu, flags);
  23276. pset = per_cpu_ptr(zone->pageset, cpu);
  23277. pcp = &pset->pcp;
  23278. - if (pcp->count) {
  23279. - free_pcppages_bulk(zone, pcp->count, pcp);
  23280. + count = pcp->count;
  23281. + if (count) {
  23282. + isolate_pcp_pages(count, pcp, &dst);
  23283. pcp->count = 0;
  23284. }
  23285. - local_irq_restore(flags);
  23286. + cpu_unlock_irqrestore(cpu, flags);
  23287. + if (count)
  23288. + free_pcppages_bulk(zone, count, &dst);
  23289. }
  23290. /*
  23291. @@ -1488,8 +1533,17 @@
  23292. else
  23293. cpumask_clear_cpu(cpu, &cpus_with_pcps);
  23294. }
  23295. +#ifndef CONFIG_PREEMPT_RT_BASE
  23296. on_each_cpu_mask(&cpus_with_pcps, (smp_call_func_t) drain_local_pages,
  23297. zone, 1);
  23298. +#else
  23299. + for_each_cpu(cpu, &cpus_with_pcps) {
  23300. + if (zone)
  23301. + drain_pages_zone(cpu, zone);
  23302. + else
  23303. + drain_pages(cpu);
  23304. + }
  23305. +#endif
  23306. }
  23307. #ifdef CONFIG_HIBERNATION
  23308. @@ -1545,7 +1599,7 @@
  23309. migratetype = get_pfnblock_migratetype(page, pfn);
  23310. set_freepage_migratetype(page, migratetype);
  23311. - local_irq_save(flags);
  23312. + local_lock_irqsave(pa_lock, flags);
  23313. __count_vm_event(PGFREE);
  23314. /*
  23315. @@ -1571,12 +1625,17 @@
  23316. pcp->count++;
  23317. if (pcp->count >= pcp->high) {
  23318. unsigned long batch = READ_ONCE(pcp->batch);
  23319. - free_pcppages_bulk(zone, batch, pcp);
  23320. + LIST_HEAD(dst);
  23321. +
  23322. + isolate_pcp_pages(batch, pcp, &dst);
  23323. pcp->count -= batch;
  23324. + local_unlock_irqrestore(pa_lock, flags);
  23325. + free_pcppages_bulk(zone, batch, &dst);
  23326. + return;
  23327. }
  23328. out:
  23329. - local_irq_restore(flags);
  23330. + local_unlock_irqrestore(pa_lock, flags);
  23331. }
  23332. /*
  23333. @@ -1707,7 +1766,7 @@
  23334. struct per_cpu_pages *pcp;
  23335. struct list_head *list;
  23336. - local_irq_save(flags);
  23337. + local_lock_irqsave(pa_lock, flags);
  23338. pcp = &this_cpu_ptr(zone->pageset)->pcp;
  23339. list = &pcp->lists[migratetype];
  23340. if (list_empty(list)) {
  23341. @@ -1739,13 +1798,15 @@
  23342. */
  23343. WARN_ON_ONCE(order > 1);
  23344. }
  23345. - spin_lock_irqsave(&zone->lock, flags);
  23346. + local_spin_lock_irqsave(pa_lock, &zone->lock, flags);
  23347. page = __rmqueue(zone, order, migratetype);
  23348. - spin_unlock(&zone->lock);
  23349. - if (!page)
  23350. + if (!page) {
  23351. + spin_unlock(&zone->lock);
  23352. goto failed;
  23353. + }
  23354. __mod_zone_freepage_state(zone, -(1 << order),
  23355. get_freepage_migratetype(page));
  23356. + spin_unlock(&zone->lock);
  23357. }
  23358. __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
  23359. @@ -1755,13 +1816,13 @@
  23360. __count_zone_vm_events(PGALLOC, zone, 1 << order);
  23361. zone_statistics(preferred_zone, zone, gfp_flags);
  23362. - local_irq_restore(flags);
  23363. + local_unlock_irqrestore(pa_lock, flags);
  23364. VM_BUG_ON_PAGE(bad_range(zone, page), page);
  23365. return page;
  23366. failed:
  23367. - local_irq_restore(flags);
  23368. + local_unlock_irqrestore(pa_lock, flags);
  23369. return NULL;
  23370. }
  23371. @@ -5650,6 +5711,7 @@
  23372. void __init page_alloc_init(void)
  23373. {
  23374. hotcpu_notifier(page_alloc_cpu_notify, 0);
  23375. + local_irq_lock_init(pa_lock);
  23376. }
  23377. /*
  23378. @@ -6544,7 +6606,7 @@
  23379. struct per_cpu_pageset *pset;
  23380. /* avoid races with drain_pages() */
  23381. - local_irq_save(flags);
  23382. + local_lock_irqsave(pa_lock, flags);
  23383. if (zone->pageset != &boot_pageset) {
  23384. for_each_online_cpu(cpu) {
  23385. pset = per_cpu_ptr(zone->pageset, cpu);
  23386. @@ -6553,7 +6615,7 @@
  23387. free_percpu(zone->pageset);
  23388. zone->pageset = &boot_pageset;
  23389. }
  23390. - local_irq_restore(flags);
  23391. + local_unlock_irqrestore(pa_lock, flags);
  23392. }
  23393. #ifdef CONFIG_MEMORY_HOTREMOVE
  23394. diff -Nur linux-4.1.6.orig/mm/slab.h linux-4.1.6/mm/slab.h
  23395. --- linux-4.1.6.orig/mm/slab.h 2015-08-17 05:52:51.000000000 +0200
  23396. +++ linux-4.1.6/mm/slab.h 2015-09-08 23:49:08.441830131 +0200
  23397. @@ -330,7 +330,11 @@
  23398. * The slab lists for all objects.
  23399. */
  23400. struct kmem_cache_node {
  23401. +#ifdef CONFIG_SLUB
  23402. + raw_spinlock_t list_lock;
  23403. +#else
  23404. spinlock_t list_lock;
  23405. +#endif
  23406. #ifdef CONFIG_SLAB
  23407. struct list_head slabs_partial; /* partial list first, better asm code */
  23408. diff -Nur linux-4.1.6.orig/mm/slub.c linux-4.1.6/mm/slub.c
  23409. --- linux-4.1.6.orig/mm/slub.c 2015-08-17 05:52:51.000000000 +0200
  23410. +++ linux-4.1.6/mm/slub.c 2015-09-08 23:49:08.441830131 +0200
  23411. @@ -1069,7 +1069,7 @@
  23412. {
  23413. struct kmem_cache_node *n = get_node(s, page_to_nid(page));
  23414. - spin_lock_irqsave(&n->list_lock, *flags);
  23415. + raw_spin_lock_irqsave(&n->list_lock, *flags);
  23416. slab_lock(page);
  23417. if (!check_slab(s, page))
  23418. @@ -1116,7 +1116,7 @@
  23419. fail:
  23420. slab_unlock(page);
  23421. - spin_unlock_irqrestore(&n->list_lock, *flags);
  23422. + raw_spin_unlock_irqrestore(&n->list_lock, *flags);
  23423. slab_fix(s, "Object at 0x%p not freed", object);
  23424. return NULL;
  23425. }
  23426. @@ -1242,6 +1242,12 @@
  23427. #endif /* CONFIG_SLUB_DEBUG */
  23428. +struct slub_free_list {
  23429. + raw_spinlock_t lock;
  23430. + struct list_head list;
  23431. +};
  23432. +static DEFINE_PER_CPU(struct slub_free_list, slub_free_list);
  23433. +
  23434. /*
  23435. * Hooks for other subsystems that check memory allocations. In a typical
  23436. * production configuration these hooks all should produce no code at all.
  23437. @@ -1306,6 +1312,17 @@
  23438. kasan_slab_free(s, x);
  23439. }
  23440. +static void setup_object(struct kmem_cache *s, struct page *page,
  23441. + void *object)
  23442. +{
  23443. + setup_object_debug(s, page, object);
  23444. + if (unlikely(s->ctor)) {
  23445. + kasan_unpoison_object_data(s, object);
  23446. + s->ctor(object);
  23447. + kasan_poison_object_data(s, object);
  23448. + }
  23449. +}
  23450. +
  23451. /*
  23452. * Slab allocation and freeing
  23453. */
  23454. @@ -1336,10 +1353,17 @@
  23455. struct page *page;
  23456. struct kmem_cache_order_objects oo = s->oo;
  23457. gfp_t alloc_gfp;
  23458. + void *start, *p;
  23459. + int idx, order;
  23460. + bool enableirqs;
  23461. flags &= gfp_allowed_mask;
  23462. - if (flags & __GFP_WAIT)
  23463. + enableirqs = (flags & __GFP_WAIT) != 0;
  23464. +#ifdef CONFIG_PREEMPT_RT_FULL
  23465. + enableirqs |= system_state == SYSTEM_RUNNING;
  23466. +#endif
  23467. + if (enableirqs)
  23468. local_irq_enable();
  23469. flags |= s->allocflags;
  23470. @@ -1359,13 +1383,13 @@
  23471. * Try a lower order alloc if possible
  23472. */
  23473. page = alloc_slab_page(s, alloc_gfp, node, oo);
  23474. -
  23475. - if (page)
  23476. - stat(s, ORDER_FALLBACK);
  23477. + if (unlikely(!page))
  23478. + goto out;
  23479. + stat(s, ORDER_FALLBACK);
  23480. }
  23481. - if (kmemcheck_enabled && page
  23482. - && !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
  23483. + if (kmemcheck_enabled &&
  23484. + !(s->flags & (SLAB_NOTRACK | DEBUG_DEFAULT_FLAGS))) {
  23485. int pages = 1 << oo_order(oo);
  23486. kmemcheck_alloc_shadow(page, oo_order(oo), alloc_gfp, node);
  23487. @@ -1380,51 +1404,9 @@
  23488. kmemcheck_mark_unallocated_pages(page, pages);
  23489. }
  23490. - if (flags & __GFP_WAIT)
  23491. - local_irq_disable();
  23492. - if (!page)
  23493. - return NULL;
  23494. -
  23495. page->objects = oo_objects(oo);
  23496. - mod_zone_page_state(page_zone(page),
  23497. - (s->flags & SLAB_RECLAIM_ACCOUNT) ?
  23498. - NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
  23499. - 1 << oo_order(oo));
  23500. -
  23501. - return page;
  23502. -}
  23503. -
  23504. -static void setup_object(struct kmem_cache *s, struct page *page,
  23505. - void *object)
  23506. -{
  23507. - setup_object_debug(s, page, object);
  23508. - if (unlikely(s->ctor)) {
  23509. - kasan_unpoison_object_data(s, object);
  23510. - s->ctor(object);
  23511. - kasan_poison_object_data(s, object);
  23512. - }
  23513. -}
  23514. -
  23515. -static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
  23516. -{
  23517. - struct page *page;
  23518. - void *start;
  23519. - void *p;
  23520. - int order;
  23521. - int idx;
  23522. -
  23523. - if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
  23524. - pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
  23525. - BUG();
  23526. - }
  23527. -
  23528. - page = allocate_slab(s,
  23529. - flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
  23530. - if (!page)
  23531. - goto out;
  23532. order = compound_order(page);
  23533. - inc_slabs_node(s, page_to_nid(page), page->objects);
  23534. page->slab_cache = s;
  23535. __SetPageSlab(page);
  23536. if (page->pfmemalloc)
  23537. @@ -1448,10 +1430,34 @@
  23538. page->freelist = start;
  23539. page->inuse = page->objects;
  23540. page->frozen = 1;
  23541. +
  23542. out:
  23543. + if (enableirqs)
  23544. + local_irq_disable();
  23545. + if (!page)
  23546. + return NULL;
  23547. +
  23548. + mod_zone_page_state(page_zone(page),
  23549. + (s->flags & SLAB_RECLAIM_ACCOUNT) ?
  23550. + NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
  23551. + 1 << oo_order(oo));
  23552. +
  23553. + inc_slabs_node(s, page_to_nid(page), page->objects);
  23554. +
  23555. return page;
  23556. }
  23557. +static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
  23558. +{
  23559. + if (unlikely(flags & GFP_SLAB_BUG_MASK)) {
  23560. + pr_emerg("gfp: %u\n", flags & GFP_SLAB_BUG_MASK);
  23561. + BUG();
  23562. + }
  23563. +
  23564. + return allocate_slab(s,
  23565. + flags & (GFP_RECLAIM_MASK | GFP_CONSTRAINT_MASK), node);
  23566. +}
  23567. +
  23568. static void __free_slab(struct kmem_cache *s, struct page *page)
  23569. {
  23570. int order = compound_order(page);
  23571. @@ -1483,6 +1489,16 @@
  23572. memcg_uncharge_slab(s, order);
  23573. }
  23574. +static void free_delayed(struct list_head *h)
  23575. +{
  23576. + while(!list_empty(h)) {
  23577. + struct page *page = list_first_entry(h, struct page, lru);
  23578. +
  23579. + list_del(&page->lru);
  23580. + __free_slab(page->slab_cache, page);
  23581. + }
  23582. +}
  23583. +
  23584. #define need_reserve_slab_rcu \
  23585. (sizeof(((struct page *)NULL)->lru) < sizeof(struct rcu_head))
  23586. @@ -1517,6 +1533,12 @@
  23587. }
  23588. call_rcu(head, rcu_free_slab);
  23589. + } else if (irqs_disabled()) {
  23590. + struct slub_free_list *f = this_cpu_ptr(&slub_free_list);
  23591. +
  23592. + raw_spin_lock(&f->lock);
  23593. + list_add(&page->lru, &f->list);
  23594. + raw_spin_unlock(&f->lock);
  23595. } else
  23596. __free_slab(s, page);
  23597. }
  23598. @@ -1630,7 +1652,7 @@
  23599. if (!n || !n->nr_partial)
  23600. return NULL;
  23601. - spin_lock(&n->list_lock);
  23602. + raw_spin_lock(&n->list_lock);
  23603. list_for_each_entry_safe(page, page2, &n->partial, lru) {
  23604. void *t;
  23605. @@ -1655,7 +1677,7 @@
  23606. break;
  23607. }
  23608. - spin_unlock(&n->list_lock);
  23609. + raw_spin_unlock(&n->list_lock);
  23610. return object;
  23611. }
  23612. @@ -1901,7 +1923,7 @@
  23613. * that acquire_slab() will see a slab page that
  23614. * is frozen
  23615. */
  23616. - spin_lock(&n->list_lock);
  23617. + raw_spin_lock(&n->list_lock);
  23618. }
  23619. } else {
  23620. m = M_FULL;
  23621. @@ -1912,7 +1934,7 @@
  23622. * slabs from diagnostic functions will not see
  23623. * any frozen slabs.
  23624. */
  23625. - spin_lock(&n->list_lock);
  23626. + raw_spin_lock(&n->list_lock);
  23627. }
  23628. }
  23629. @@ -1947,7 +1969,7 @@
  23630. goto redo;
  23631. if (lock)
  23632. - spin_unlock(&n->list_lock);
  23633. + raw_spin_unlock(&n->list_lock);
  23634. if (m == M_FREE) {
  23635. stat(s, DEACTIVATE_EMPTY);
  23636. @@ -1979,10 +2001,10 @@
  23637. n2 = get_node(s, page_to_nid(page));
  23638. if (n != n2) {
  23639. if (n)
  23640. - spin_unlock(&n->list_lock);
  23641. + raw_spin_unlock(&n->list_lock);
  23642. n = n2;
  23643. - spin_lock(&n->list_lock);
  23644. + raw_spin_lock(&n->list_lock);
  23645. }
  23646. do {
  23647. @@ -2011,7 +2033,7 @@
  23648. }
  23649. if (n)
  23650. - spin_unlock(&n->list_lock);
  23651. + raw_spin_unlock(&n->list_lock);
  23652. while (discard_page) {
  23653. page = discard_page;
  23654. @@ -2050,14 +2072,21 @@
  23655. pobjects = oldpage->pobjects;
  23656. pages = oldpage->pages;
  23657. if (drain && pobjects > s->cpu_partial) {
  23658. + struct slub_free_list *f;
  23659. unsigned long flags;
  23660. + LIST_HEAD(tofree);
  23661. /*
  23662. * partial array is full. Move the existing
  23663. * set to the per node partial list.
  23664. */
  23665. local_irq_save(flags);
  23666. unfreeze_partials(s, this_cpu_ptr(s->cpu_slab));
  23667. + f = this_cpu_ptr(&slub_free_list);
  23668. + raw_spin_lock(&f->lock);
  23669. + list_splice_init(&f->list, &tofree);
  23670. + raw_spin_unlock(&f->lock);
  23671. local_irq_restore(flags);
  23672. + free_delayed(&tofree);
  23673. oldpage = NULL;
  23674. pobjects = 0;
  23675. pages = 0;
  23676. @@ -2129,7 +2158,22 @@
  23677. static void flush_all(struct kmem_cache *s)
  23678. {
  23679. + LIST_HEAD(tofree);
  23680. + int cpu;
  23681. +
  23682. on_each_cpu_cond(has_cpu_slab, flush_cpu_slab, s, 1, GFP_ATOMIC);
  23683. + for_each_online_cpu(cpu) {
  23684. + struct slub_free_list *f;
  23685. +
  23686. + if (!has_cpu_slab(cpu, s))
  23687. + continue;
  23688. +
  23689. + f = &per_cpu(slub_free_list, cpu);
  23690. + raw_spin_lock_irq(&f->lock);
  23691. + list_splice_init(&f->list, &tofree);
  23692. + raw_spin_unlock_irq(&f->lock);
  23693. + free_delayed(&tofree);
  23694. + }
  23695. }
  23696. /*
  23697. @@ -2165,10 +2209,10 @@
  23698. unsigned long x = 0;
  23699. struct page *page;
  23700. - spin_lock_irqsave(&n->list_lock, flags);
  23701. + raw_spin_lock_irqsave(&n->list_lock, flags);
  23702. list_for_each_entry(page, &n->partial, lru)
  23703. x += get_count(page);
  23704. - spin_unlock_irqrestore(&n->list_lock, flags);
  23705. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23706. return x;
  23707. }
  23708. #endif /* CONFIG_SLUB_DEBUG || CONFIG_SYSFS */
  23709. @@ -2305,9 +2349,11 @@
  23710. static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
  23711. unsigned long addr, struct kmem_cache_cpu *c)
  23712. {
  23713. + struct slub_free_list *f;
  23714. void *freelist;
  23715. struct page *page;
  23716. unsigned long flags;
  23717. + LIST_HEAD(tofree);
  23718. local_irq_save(flags);
  23719. #ifdef CONFIG_PREEMPT
  23720. @@ -2375,7 +2421,13 @@
  23721. VM_BUG_ON(!c->page->frozen);
  23722. c->freelist = get_freepointer(s, freelist);
  23723. c->tid = next_tid(c->tid);
  23724. +out:
  23725. + f = this_cpu_ptr(&slub_free_list);
  23726. + raw_spin_lock(&f->lock);
  23727. + list_splice_init(&f->list, &tofree);
  23728. + raw_spin_unlock(&f->lock);
  23729. local_irq_restore(flags);
  23730. + free_delayed(&tofree);
  23731. return freelist;
  23732. new_slab:
  23733. @@ -2392,8 +2444,7 @@
  23734. if (unlikely(!freelist)) {
  23735. slab_out_of_memory(s, gfpflags, node);
  23736. - local_irq_restore(flags);
  23737. - return NULL;
  23738. + goto out;
  23739. }
  23740. page = c->page;
  23741. @@ -2408,8 +2459,7 @@
  23742. deactivate_slab(s, page, get_freepointer(s, freelist));
  23743. c->page = NULL;
  23744. c->freelist = NULL;
  23745. - local_irq_restore(flags);
  23746. - return freelist;
  23747. + goto out;
  23748. }
  23749. /*
  23750. @@ -2593,7 +2643,7 @@
  23751. do {
  23752. if (unlikely(n)) {
  23753. - spin_unlock_irqrestore(&n->list_lock, flags);
  23754. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23755. n = NULL;
  23756. }
  23757. prior = page->freelist;
  23758. @@ -2625,7 +2675,7 @@
  23759. * Otherwise the list_lock will synchronize with
  23760. * other processors updating the list of slabs.
  23761. */
  23762. - spin_lock_irqsave(&n->list_lock, flags);
  23763. + raw_spin_lock_irqsave(&n->list_lock, flags);
  23764. }
  23765. }
  23766. @@ -2667,7 +2717,7 @@
  23767. add_partial(n, page, DEACTIVATE_TO_TAIL);
  23768. stat(s, FREE_ADD_PARTIAL);
  23769. }
  23770. - spin_unlock_irqrestore(&n->list_lock, flags);
  23771. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23772. return;
  23773. slab_empty:
  23774. @@ -2682,7 +2732,7 @@
  23775. remove_full(s, n, page);
  23776. }
  23777. - spin_unlock_irqrestore(&n->list_lock, flags);
  23778. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23779. stat(s, FREE_SLAB);
  23780. discard_slab(s, page);
  23781. }
  23782. @@ -2881,7 +2931,7 @@
  23783. init_kmem_cache_node(struct kmem_cache_node *n)
  23784. {
  23785. n->nr_partial = 0;
  23786. - spin_lock_init(&n->list_lock);
  23787. + raw_spin_lock_init(&n->list_lock);
  23788. INIT_LIST_HEAD(&n->partial);
  23789. #ifdef CONFIG_SLUB_DEBUG
  23790. atomic_long_set(&n->nr_slabs, 0);
  23791. @@ -3463,7 +3513,7 @@
  23792. for (i = 0; i < SHRINK_PROMOTE_MAX; i++)
  23793. INIT_LIST_HEAD(promote + i);
  23794. - spin_lock_irqsave(&n->list_lock, flags);
  23795. + raw_spin_lock_irqsave(&n->list_lock, flags);
  23796. /*
  23797. * Build lists of slabs to discard or promote.
  23798. @@ -3494,7 +3544,7 @@
  23799. for (i = SHRINK_PROMOTE_MAX - 1; i >= 0; i--)
  23800. list_splice(promote + i, &n->partial);
  23801. - spin_unlock_irqrestore(&n->list_lock, flags);
  23802. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23803. /* Release empty slabs */
  23804. list_for_each_entry_safe(page, t, &discard, lru)
  23805. @@ -3670,6 +3720,12 @@
  23806. {
  23807. static __initdata struct kmem_cache boot_kmem_cache,
  23808. boot_kmem_cache_node;
  23809. + int cpu;
  23810. +
  23811. + for_each_possible_cpu(cpu) {
  23812. + raw_spin_lock_init(&per_cpu(slub_free_list, cpu).lock);
  23813. + INIT_LIST_HEAD(&per_cpu(slub_free_list, cpu).list);
  23814. + }
  23815. if (debug_guardpage_minorder())
  23816. slub_max_order = 0;
  23817. @@ -3912,7 +3968,7 @@
  23818. struct page *page;
  23819. unsigned long flags;
  23820. - spin_lock_irqsave(&n->list_lock, flags);
  23821. + raw_spin_lock_irqsave(&n->list_lock, flags);
  23822. list_for_each_entry(page, &n->partial, lru) {
  23823. validate_slab_slab(s, page, map);
  23824. @@ -3934,7 +3990,7 @@
  23825. s->name, count, atomic_long_read(&n->nr_slabs));
  23826. out:
  23827. - spin_unlock_irqrestore(&n->list_lock, flags);
  23828. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23829. return count;
  23830. }
  23831. @@ -4122,12 +4178,12 @@
  23832. if (!atomic_long_read(&n->nr_slabs))
  23833. continue;
  23834. - spin_lock_irqsave(&n->list_lock, flags);
  23835. + raw_spin_lock_irqsave(&n->list_lock, flags);
  23836. list_for_each_entry(page, &n->partial, lru)
  23837. process_slab(&t, s, page, alloc, map);
  23838. list_for_each_entry(page, &n->full, lru)
  23839. process_slab(&t, s, page, alloc, map);
  23840. - spin_unlock_irqrestore(&n->list_lock, flags);
  23841. + raw_spin_unlock_irqrestore(&n->list_lock, flags);
  23842. }
  23843. for (i = 0; i < t.count; i++) {
  23844. diff -Nur linux-4.1.6.orig/mm/swap.c linux-4.1.6/mm/swap.c
  23845. --- linux-4.1.6.orig/mm/swap.c 2015-08-17 05:52:51.000000000 +0200
  23846. +++ linux-4.1.6/mm/swap.c 2015-09-08 23:49:08.441830131 +0200
  23847. @@ -32,6 +32,7 @@
  23848. #include <linux/gfp.h>
  23849. #include <linux/uio.h>
  23850. #include <linux/hugetlb.h>
  23851. +#include <linux/locallock.h>
  23852. #include "internal.h"
  23853. @@ -45,6 +46,9 @@
  23854. static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
  23855. static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs);
  23856. +static DEFINE_LOCAL_IRQ_LOCK(rotate_lock);
  23857. +DEFINE_LOCAL_IRQ_LOCK(swapvec_lock);
  23858. +
  23859. /*
  23860. * This path almost never happens for VM activity - pages are normally
  23861. * freed via pagevecs. But it gets used by networking.
  23862. @@ -481,11 +485,11 @@
  23863. unsigned long flags;
  23864. page_cache_get(page);
  23865. - local_irq_save(flags);
  23866. + local_lock_irqsave(rotate_lock, flags);
  23867. pvec = this_cpu_ptr(&lru_rotate_pvecs);
  23868. if (!pagevec_add(pvec, page))
  23869. pagevec_move_tail(pvec);
  23870. - local_irq_restore(flags);
  23871. + local_unlock_irqrestore(rotate_lock, flags);
  23872. }
  23873. }
  23874. @@ -536,12 +540,13 @@
  23875. void activate_page(struct page *page)
  23876. {
  23877. if (PageLRU(page) && !PageActive(page) && !PageUnevictable(page)) {
  23878. - struct pagevec *pvec = &get_cpu_var(activate_page_pvecs);
  23879. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  23880. + activate_page_pvecs);
  23881. page_cache_get(page);
  23882. if (!pagevec_add(pvec, page))
  23883. pagevec_lru_move_fn(pvec, __activate_page, NULL);
  23884. - put_cpu_var(activate_page_pvecs);
  23885. + put_locked_var(swapvec_lock, activate_page_pvecs);
  23886. }
  23887. }
  23888. @@ -567,7 +572,7 @@
  23889. static void __lru_cache_activate_page(struct page *page)
  23890. {
  23891. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  23892. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  23893. int i;
  23894. /*
  23895. @@ -589,7 +594,7 @@
  23896. }
  23897. }
  23898. - put_cpu_var(lru_add_pvec);
  23899. + put_locked_var(swapvec_lock, lru_add_pvec);
  23900. }
  23901. /*
  23902. @@ -628,13 +633,13 @@
  23903. static void __lru_cache_add(struct page *page)
  23904. {
  23905. - struct pagevec *pvec = &get_cpu_var(lru_add_pvec);
  23906. + struct pagevec *pvec = &get_locked_var(swapvec_lock, lru_add_pvec);
  23907. page_cache_get(page);
  23908. if (!pagevec_space(pvec))
  23909. __pagevec_lru_add(pvec);
  23910. pagevec_add(pvec, page);
  23911. - put_cpu_var(lru_add_pvec);
  23912. + put_locked_var(swapvec_lock, lru_add_pvec);
  23913. }
  23914. /**
  23915. @@ -814,9 +819,9 @@
  23916. unsigned long flags;
  23917. /* No harm done if a racing interrupt already did this */
  23918. - local_irq_save(flags);
  23919. + local_lock_irqsave(rotate_lock, flags);
  23920. pagevec_move_tail(pvec);
  23921. - local_irq_restore(flags);
  23922. + local_unlock_irqrestore(rotate_lock, flags);
  23923. }
  23924. pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
  23925. @@ -844,18 +849,19 @@
  23926. return;
  23927. if (likely(get_page_unless_zero(page))) {
  23928. - struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
  23929. + struct pagevec *pvec = &get_locked_var(swapvec_lock,
  23930. + lru_deactivate_file_pvecs);
  23931. if (!pagevec_add(pvec, page))
  23932. pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
  23933. - put_cpu_var(lru_deactivate_file_pvecs);
  23934. + put_locked_var(swapvec_lock, lru_deactivate_file_pvecs);
  23935. }
  23936. }
  23937. void lru_add_drain(void)
  23938. {
  23939. - lru_add_drain_cpu(get_cpu());
  23940. - put_cpu();
  23941. + lru_add_drain_cpu(local_lock_cpu(swapvec_lock));
  23942. + local_unlock_cpu(swapvec_lock);
  23943. }
  23944. static void lru_add_drain_per_cpu(struct work_struct *dummy)
  23945. diff -Nur linux-4.1.6.orig/mm/truncate.c linux-4.1.6/mm/truncate.c
  23946. --- linux-4.1.6.orig/mm/truncate.c 2015-08-17 05:52:51.000000000 +0200
  23947. +++ linux-4.1.6/mm/truncate.c 2015-09-08 23:49:08.441830131 +0200
  23948. @@ -56,8 +56,11 @@
  23949. * protected by mapping->tree_lock.
  23950. */
  23951. if (!workingset_node_shadows(node) &&
  23952. - !list_empty(&node->private_list))
  23953. - list_lru_del(&workingset_shadow_nodes, &node->private_list);
  23954. + !list_empty(&node->private_list)) {
  23955. + local_lock(workingset_shadow_lock);
  23956. + list_lru_del(&__workingset_shadow_nodes, &node->private_list);
  23957. + local_unlock(workingset_shadow_lock);
  23958. + }
  23959. __radix_tree_delete_node(&mapping->page_tree, node);
  23960. unlock:
  23961. spin_unlock_irq(&mapping->tree_lock);
  23962. diff -Nur linux-4.1.6.orig/mm/vmalloc.c linux-4.1.6/mm/vmalloc.c
  23963. --- linux-4.1.6.orig/mm/vmalloc.c 2015-08-17 05:52:51.000000000 +0200
  23964. +++ linux-4.1.6/mm/vmalloc.c 2015-09-08 23:49:08.441830131 +0200
  23965. @@ -819,7 +819,7 @@
  23966. struct vmap_block *vb;
  23967. struct vmap_area *va;
  23968. unsigned long vb_idx;
  23969. - int node, err;
  23970. + int node, err, cpu;
  23971. void *vaddr;
  23972. node = numa_node_id();
  23973. @@ -862,11 +862,12 @@
  23974. BUG_ON(err);
  23975. radix_tree_preload_end();
  23976. - vbq = &get_cpu_var(vmap_block_queue);
  23977. + cpu = get_cpu_light();
  23978. + vbq = this_cpu_ptr(&vmap_block_queue);
  23979. spin_lock(&vbq->lock);
  23980. list_add_tail_rcu(&vb->free_list, &vbq->free);
  23981. spin_unlock(&vbq->lock);
  23982. - put_cpu_var(vmap_block_queue);
  23983. + put_cpu_light();
  23984. return vaddr;
  23985. }
  23986. @@ -935,6 +936,7 @@
  23987. struct vmap_block *vb;
  23988. void *vaddr = NULL;
  23989. unsigned int order;
  23990. + int cpu;
  23991. BUG_ON(size & ~PAGE_MASK);
  23992. BUG_ON(size > PAGE_SIZE*VMAP_MAX_ALLOC);
  23993. @@ -949,7 +951,8 @@
  23994. order = get_order(size);
  23995. rcu_read_lock();
  23996. - vbq = &get_cpu_var(vmap_block_queue);
  23997. + cpu = get_cpu_light();
  23998. + vbq = this_cpu_ptr(&vmap_block_queue);
  23999. list_for_each_entry_rcu(vb, &vbq->free, free_list) {
  24000. unsigned long pages_off;
  24001. @@ -972,7 +975,7 @@
  24002. break;
  24003. }
  24004. - put_cpu_var(vmap_block_queue);
  24005. + put_cpu_light();
  24006. rcu_read_unlock();
  24007. /* Allocate new block if nothing was found */
  24008. diff -Nur linux-4.1.6.orig/mm/vmstat.c linux-4.1.6/mm/vmstat.c
  24009. --- linux-4.1.6.orig/mm/vmstat.c 2015-08-17 05:52:51.000000000 +0200
  24010. +++ linux-4.1.6/mm/vmstat.c 2015-09-08 23:49:08.441830131 +0200
  24011. @@ -226,6 +226,7 @@
  24012. long x;
  24013. long t;
  24014. + preempt_disable_rt();
  24015. x = delta + __this_cpu_read(*p);
  24016. t = __this_cpu_read(pcp->stat_threshold);
  24017. @@ -235,6 +236,7 @@
  24018. x = 0;
  24019. }
  24020. __this_cpu_write(*p, x);
  24021. + preempt_enable_rt();
  24022. }
  24023. EXPORT_SYMBOL(__mod_zone_page_state);
  24024. @@ -267,6 +269,7 @@
  24025. s8 __percpu *p = pcp->vm_stat_diff + item;
  24026. s8 v, t;
  24027. + preempt_disable_rt();
  24028. v = __this_cpu_inc_return(*p);
  24029. t = __this_cpu_read(pcp->stat_threshold);
  24030. if (unlikely(v > t)) {
  24031. @@ -275,6 +278,7 @@
  24032. zone_page_state_add(v + overstep, zone, item);
  24033. __this_cpu_write(*p, -overstep);
  24034. }
  24035. + preempt_enable_rt();
  24036. }
  24037. void __inc_zone_page_state(struct page *page, enum zone_stat_item item)
  24038. @@ -289,6 +293,7 @@
  24039. s8 __percpu *p = pcp->vm_stat_diff + item;
  24040. s8 v, t;
  24041. + preempt_disable_rt();
  24042. v = __this_cpu_dec_return(*p);
  24043. t = __this_cpu_read(pcp->stat_threshold);
  24044. if (unlikely(v < - t)) {
  24045. @@ -297,6 +302,7 @@
  24046. zone_page_state_add(v - overstep, zone, item);
  24047. __this_cpu_write(*p, overstep);
  24048. }
  24049. + preempt_enable_rt();
  24050. }
  24051. void __dec_zone_page_state(struct page *page, enum zone_stat_item item)
  24052. diff -Nur linux-4.1.6.orig/mm/workingset.c linux-4.1.6/mm/workingset.c
  24053. --- linux-4.1.6.orig/mm/workingset.c 2015-08-17 05:52:51.000000000 +0200
  24054. +++ linux-4.1.6/mm/workingset.c 2015-09-08 23:49:08.441830131 +0200
  24055. @@ -264,7 +264,8 @@
  24056. * point where they would still be useful.
  24057. */
  24058. -struct list_lru workingset_shadow_nodes;
  24059. +struct list_lru __workingset_shadow_nodes;
  24060. +DEFINE_LOCAL_IRQ_LOCK(workingset_shadow_lock);
  24061. static unsigned long count_shadow_nodes(struct shrinker *shrinker,
  24062. struct shrink_control *sc)
  24063. @@ -274,9 +275,9 @@
  24064. unsigned long pages;
  24065. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  24066. - local_irq_disable();
  24067. - shadow_nodes = list_lru_shrink_count(&workingset_shadow_nodes, sc);
  24068. - local_irq_enable();
  24069. + local_lock_irq(workingset_shadow_lock);
  24070. + shadow_nodes = list_lru_shrink_count(&__workingset_shadow_nodes, sc);
  24071. + local_unlock_irq(workingset_shadow_lock);
  24072. pages = node_present_pages(sc->nid);
  24073. /*
  24074. @@ -363,9 +364,9 @@
  24075. spin_unlock(&mapping->tree_lock);
  24076. ret = LRU_REMOVED_RETRY;
  24077. out:
  24078. - local_irq_enable();
  24079. + local_unlock_irq(workingset_shadow_lock);
  24080. cond_resched();
  24081. - local_irq_disable();
  24082. + local_lock_irq(workingset_shadow_lock);
  24083. spin_lock(lru_lock);
  24084. return ret;
  24085. }
  24086. @@ -376,10 +377,10 @@
  24087. unsigned long ret;
  24088. /* list_lru lock nests inside IRQ-safe mapping->tree_lock */
  24089. - local_irq_disable();
  24090. - ret = list_lru_shrink_walk(&workingset_shadow_nodes, sc,
  24091. + local_lock_irq(workingset_shadow_lock);
  24092. + ret = list_lru_shrink_walk(&__workingset_shadow_nodes, sc,
  24093. shadow_lru_isolate, NULL);
  24094. - local_irq_enable();
  24095. + local_unlock_irq(workingset_shadow_lock);
  24096. return ret;
  24097. }
  24098. @@ -400,7 +401,7 @@
  24099. {
  24100. int ret;
  24101. - ret = list_lru_init_key(&workingset_shadow_nodes, &shadow_nodes_key);
  24102. + ret = list_lru_init_key(&__workingset_shadow_nodes, &shadow_nodes_key);
  24103. if (ret)
  24104. goto err;
  24105. ret = register_shrinker(&workingset_shadow_shrinker);
  24106. @@ -408,7 +409,7 @@
  24107. goto err_list_lru;
  24108. return 0;
  24109. err_list_lru:
  24110. - list_lru_destroy(&workingset_shadow_nodes);
  24111. + list_lru_destroy(&__workingset_shadow_nodes);
  24112. err:
  24113. return ret;
  24114. }
  24115. diff -Nur linux-4.1.6.orig/net/core/dev.c linux-4.1.6/net/core/dev.c
  24116. --- linux-4.1.6.orig/net/core/dev.c 2015-08-17 05:52:51.000000000 +0200
  24117. +++ linux-4.1.6/net/core/dev.c 2015-09-08 23:49:08.441830131 +0200
  24118. @@ -184,6 +184,7 @@
  24119. static DEFINE_HASHTABLE(napi_hash, 8);
  24120. static seqcount_t devnet_rename_seq;
  24121. +static DEFINE_MUTEX(devnet_rename_mutex);
  24122. static inline void dev_base_seq_inc(struct net *net)
  24123. {
  24124. @@ -205,14 +206,14 @@
  24125. static inline void rps_lock(struct softnet_data *sd)
  24126. {
  24127. #ifdef CONFIG_RPS
  24128. - spin_lock(&sd->input_pkt_queue.lock);
  24129. + raw_spin_lock(&sd->input_pkt_queue.raw_lock);
  24130. #endif
  24131. }
  24132. static inline void rps_unlock(struct softnet_data *sd)
  24133. {
  24134. #ifdef CONFIG_RPS
  24135. - spin_unlock(&sd->input_pkt_queue.lock);
  24136. + raw_spin_unlock(&sd->input_pkt_queue.raw_lock);
  24137. #endif
  24138. }
  24139. @@ -856,7 +857,8 @@
  24140. strcpy(name, dev->name);
  24141. rcu_read_unlock();
  24142. if (read_seqcount_retry(&devnet_rename_seq, seq)) {
  24143. - cond_resched();
  24144. + mutex_lock(&devnet_rename_mutex);
  24145. + mutex_unlock(&devnet_rename_mutex);
  24146. goto retry;
  24147. }
  24148. @@ -1125,20 +1127,17 @@
  24149. if (dev->flags & IFF_UP)
  24150. return -EBUSY;
  24151. - write_seqcount_begin(&devnet_rename_seq);
  24152. + mutex_lock(&devnet_rename_mutex);
  24153. + __raw_write_seqcount_begin(&devnet_rename_seq);
  24154. - if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
  24155. - write_seqcount_end(&devnet_rename_seq);
  24156. - return 0;
  24157. - }
  24158. + if (strncmp(newname, dev->name, IFNAMSIZ) == 0)
  24159. + goto outunlock;
  24160. memcpy(oldname, dev->name, IFNAMSIZ);
  24161. err = dev_get_valid_name(net, dev, newname);
  24162. - if (err < 0) {
  24163. - write_seqcount_end(&devnet_rename_seq);
  24164. - return err;
  24165. - }
  24166. + if (err < 0)
  24167. + goto outunlock;
  24168. if (oldname[0] && !strchr(oldname, '%'))
  24169. netdev_info(dev, "renamed from %s\n", oldname);
  24170. @@ -1151,11 +1150,12 @@
  24171. if (ret) {
  24172. memcpy(dev->name, oldname, IFNAMSIZ);
  24173. dev->name_assign_type = old_assign_type;
  24174. - write_seqcount_end(&devnet_rename_seq);
  24175. - return ret;
  24176. + err = ret;
  24177. + goto outunlock;
  24178. }
  24179. - write_seqcount_end(&devnet_rename_seq);
  24180. + __raw_write_seqcount_end(&devnet_rename_seq);
  24181. + mutex_unlock(&devnet_rename_mutex);
  24182. netdev_adjacent_rename_links(dev, oldname);
  24183. @@ -1176,7 +1176,8 @@
  24184. /* err >= 0 after dev_alloc_name() or stores the first errno */
  24185. if (err >= 0) {
  24186. err = ret;
  24187. - write_seqcount_begin(&devnet_rename_seq);
  24188. + mutex_lock(&devnet_rename_mutex);
  24189. + __raw_write_seqcount_begin(&devnet_rename_seq);
  24190. memcpy(dev->name, oldname, IFNAMSIZ);
  24191. memcpy(oldname, newname, IFNAMSIZ);
  24192. dev->name_assign_type = old_assign_type;
  24193. @@ -1189,6 +1190,11 @@
  24194. }
  24195. return err;
  24196. +
  24197. +outunlock:
  24198. + __raw_write_seqcount_end(&devnet_rename_seq);
  24199. + mutex_unlock(&devnet_rename_mutex);
  24200. + return err;
  24201. }
  24202. /**
  24203. @@ -2218,6 +2224,7 @@
  24204. sd->output_queue_tailp = &q->next_sched;
  24205. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  24206. local_irq_restore(flags);
  24207. + preempt_check_resched_rt();
  24208. }
  24209. void __netif_schedule(struct Qdisc *q)
  24210. @@ -2299,6 +2306,7 @@
  24211. __this_cpu_write(softnet_data.completion_queue, skb);
  24212. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  24213. local_irq_restore(flags);
  24214. + preempt_check_resched_rt();
  24215. }
  24216. EXPORT_SYMBOL(__dev_kfree_skb_irq);
  24217. @@ -3366,6 +3374,7 @@
  24218. rps_unlock(sd);
  24219. local_irq_restore(flags);
  24220. + preempt_check_resched_rt();
  24221. atomic_long_inc(&skb->dev->rx_dropped);
  24222. kfree_skb(skb);
  24223. @@ -3384,7 +3393,7 @@
  24224. struct rps_dev_flow voidflow, *rflow = &voidflow;
  24225. int cpu;
  24226. - preempt_disable();
  24227. + migrate_disable();
  24228. rcu_read_lock();
  24229. cpu = get_rps_cpu(skb->dev, skb, &rflow);
  24230. @@ -3394,13 +3403,13 @@
  24231. ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail);
  24232. rcu_read_unlock();
  24233. - preempt_enable();
  24234. + migrate_enable();
  24235. } else
  24236. #endif
  24237. {
  24238. unsigned int qtail;
  24239. - ret = enqueue_to_backlog(skb, get_cpu(), &qtail);
  24240. - put_cpu();
  24241. + ret = enqueue_to_backlog(skb, get_cpu_light(), &qtail);
  24242. + put_cpu_light();
  24243. }
  24244. return ret;
  24245. }
  24246. @@ -3434,16 +3443,44 @@
  24247. trace_netif_rx_ni_entry(skb);
  24248. - preempt_disable();
  24249. + local_bh_disable();
  24250. err = netif_rx_internal(skb);
  24251. - if (local_softirq_pending())
  24252. - do_softirq();
  24253. - preempt_enable();
  24254. + local_bh_enable();
  24255. return err;
  24256. }
  24257. EXPORT_SYMBOL(netif_rx_ni);
  24258. +#ifdef CONFIG_PREEMPT_RT_FULL
  24259. +/*
  24260. + * RT runs ksoftirqd as a real time thread and the root_lock is a
  24261. + * "sleeping spinlock". If the trylock fails then we can go into an
  24262. + * infinite loop when ksoftirqd preempted the task which actually
  24263. + * holds the lock, because we requeue q and raise NET_TX softirq
  24264. + * causing ksoftirqd to loop forever.
  24265. + *
  24266. + * It's safe to use spin_lock on RT here as softirqs run in thread
  24267. + * context and cannot deadlock against the thread which is holding
  24268. + * root_lock.
  24269. + *
  24270. + * On !RT the trylock might fail, but there we bail out from the
  24271. + * softirq loop after 10 attempts which we can't do on RT. And the
  24272. + * task holding root_lock cannot be preempted, so the only downside of
  24273. + * that trylock is that we need 10 loops to decide that we should have
  24274. + * given up in the first one :)
  24275. + */
  24276. +static inline int take_root_lock(spinlock_t *lock)
  24277. +{
  24278. + spin_lock(lock);
  24279. + return 1;
  24280. +}
  24281. +#else
  24282. +static inline int take_root_lock(spinlock_t *lock)
  24283. +{
  24284. + return spin_trylock(lock);
  24285. +}
  24286. +#endif
  24287. +
  24288. static void net_tx_action(struct softirq_action *h)
  24289. {
  24290. struct softnet_data *sd = this_cpu_ptr(&softnet_data);
  24291. @@ -3485,7 +3522,7 @@
  24292. head = head->next_sched;
  24293. root_lock = qdisc_lock(q);
  24294. - if (spin_trylock(root_lock)) {
  24295. + if (take_root_lock(root_lock)) {
  24296. smp_mb__before_atomic();
  24297. clear_bit(__QDISC_STATE_SCHED,
  24298. &q->state);
  24299. @@ -3884,7 +3921,7 @@
  24300. skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) {
  24301. if (skb->dev == dev) {
  24302. __skb_unlink(skb, &sd->input_pkt_queue);
  24303. - kfree_skb(skb);
  24304. + __skb_queue_tail(&sd->tofree_queue, skb);
  24305. input_queue_head_incr(sd);
  24306. }
  24307. }
  24308. @@ -3893,10 +3930,13 @@
  24309. skb_queue_walk_safe(&sd->process_queue, skb, tmp) {
  24310. if (skb->dev == dev) {
  24311. __skb_unlink(skb, &sd->process_queue);
  24312. - kfree_skb(skb);
  24313. + __skb_queue_tail(&sd->tofree_queue, skb);
  24314. input_queue_head_incr(sd);
  24315. }
  24316. }
  24317. +
  24318. + if (!skb_queue_empty(&sd->tofree_queue))
  24319. + raise_softirq_irqoff(NET_RX_SOFTIRQ);
  24320. }
  24321. static int napi_gro_complete(struct sk_buff *skb)
  24322. @@ -4347,6 +4387,7 @@
  24323. sd->rps_ipi_list = NULL;
  24324. local_irq_enable();
  24325. + preempt_check_resched_rt();
  24326. /* Send pending IPI's to kick RPS processing on remote cpus. */
  24327. while (remsd) {
  24328. @@ -4360,6 +4401,7 @@
  24329. } else
  24330. #endif
  24331. local_irq_enable();
  24332. + preempt_check_resched_rt();
  24333. }
  24334. static bool sd_has_rps_ipi_waiting(struct softnet_data *sd)
  24335. @@ -4439,6 +4481,7 @@
  24336. local_irq_save(flags);
  24337. ____napi_schedule(this_cpu_ptr(&softnet_data), n);
  24338. local_irq_restore(flags);
  24339. + preempt_check_resched_rt();
  24340. }
  24341. EXPORT_SYMBOL(__napi_schedule);
  24342. @@ -7168,6 +7211,7 @@
  24343. raise_softirq_irqoff(NET_TX_SOFTIRQ);
  24344. local_irq_enable();
  24345. + preempt_check_resched_rt();
  24346. /* Process offline CPU's input_pkt_queue */
  24347. while ((skb = __skb_dequeue(&oldsd->process_queue))) {
  24348. @@ -7178,6 +7222,9 @@
  24349. netif_rx_ni(skb);
  24350. input_queue_head_incr(oldsd);
  24351. }
  24352. + while ((skb = __skb_dequeue(&oldsd->tofree_queue))) {
  24353. + kfree_skb(skb);
  24354. + }
  24355. return NOTIFY_OK;
  24356. }
  24357. @@ -7479,8 +7526,9 @@
  24358. for_each_possible_cpu(i) {
  24359. struct softnet_data *sd = &per_cpu(softnet_data, i);
  24360. - skb_queue_head_init(&sd->input_pkt_queue);
  24361. - skb_queue_head_init(&sd->process_queue);
  24362. + skb_queue_head_init_raw(&sd->input_pkt_queue);
  24363. + skb_queue_head_init_raw(&sd->process_queue);
  24364. + skb_queue_head_init_raw(&sd->tofree_queue);
  24365. INIT_LIST_HEAD(&sd->poll_list);
  24366. sd->output_queue_tailp = &sd->output_queue;
  24367. #ifdef CONFIG_RPS
  24368. diff -Nur linux-4.1.6.orig/net/core/skbuff.c linux-4.1.6/net/core/skbuff.c
  24369. --- linux-4.1.6.orig/net/core/skbuff.c 2015-08-17 05:52:51.000000000 +0200
  24370. +++ linux-4.1.6/net/core/skbuff.c 2015-09-08 23:49:08.445829687 +0200
  24371. @@ -63,6 +63,7 @@
  24372. #include <linux/errqueue.h>
  24373. #include <linux/prefetch.h>
  24374. #include <linux/if_vlan.h>
  24375. +#include <linux/locallock.h>
  24376. #include <net/protocol.h>
  24377. #include <net/dst.h>
  24378. @@ -356,6 +357,7 @@
  24379. };
  24380. static DEFINE_PER_CPU(struct netdev_alloc_cache, netdev_alloc_cache);
  24381. static DEFINE_PER_CPU(struct netdev_alloc_cache, napi_alloc_cache);
  24382. +static DEFINE_LOCAL_IRQ_LOCK(netdev_alloc_lock);
  24383. static struct page *__page_frag_refill(struct netdev_alloc_cache *nc,
  24384. gfp_t gfp_mask)
  24385. @@ -433,9 +435,9 @@
  24386. unsigned long flags;
  24387. void *data;
  24388. - local_irq_save(flags);
  24389. + local_lock_irqsave(netdev_alloc_lock, flags);
  24390. data = __alloc_page_frag(&netdev_alloc_cache, fragsz, gfp_mask);
  24391. - local_irq_restore(flags);
  24392. + local_unlock_irqrestore(netdev_alloc_lock, flags);
  24393. return data;
  24394. }
  24395. diff -Nur linux-4.1.6.orig/net/core/sock.c linux-4.1.6/net/core/sock.c
  24396. --- linux-4.1.6.orig/net/core/sock.c 2015-08-17 05:52:51.000000000 +0200
  24397. +++ linux-4.1.6/net/core/sock.c 2015-09-08 23:49:08.445829687 +0200
  24398. @@ -2370,12 +2370,11 @@
  24399. if (sk->sk_lock.owned)
  24400. __lock_sock(sk);
  24401. sk->sk_lock.owned = 1;
  24402. - spin_unlock(&sk->sk_lock.slock);
  24403. + spin_unlock_bh(&sk->sk_lock.slock);
  24404. /*
  24405. * The sk_lock has mutex_lock() semantics here:
  24406. */
  24407. mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_);
  24408. - local_bh_enable();
  24409. }
  24410. EXPORT_SYMBOL(lock_sock_nested);
  24411. diff -Nur linux-4.1.6.orig/net/ipv4/icmp.c linux-4.1.6/net/ipv4/icmp.c
  24412. --- linux-4.1.6.orig/net/ipv4/icmp.c 2015-08-17 05:52:51.000000000 +0200
  24413. +++ linux-4.1.6/net/ipv4/icmp.c 2015-09-08 23:49:08.461827913 +0200
  24414. @@ -69,6 +69,7 @@
  24415. #include <linux/jiffies.h>
  24416. #include <linux/kernel.h>
  24417. #include <linux/fcntl.h>
  24418. +#include <linux/sysrq.h>
  24419. #include <linux/socket.h>
  24420. #include <linux/in.h>
  24421. #include <linux/inet.h>
  24422. @@ -867,6 +868,30 @@
  24423. }
  24424. /*
  24425. + * 32bit and 64bit have different timestamp length, so we check for
  24426. + * the cookie at offset 20 and verify it is repeated at offset 50
  24427. + */
  24428. +#define CO_POS0 20
  24429. +#define CO_POS1 50
  24430. +#define CO_SIZE sizeof(int)
  24431. +#define ICMP_SYSRQ_SIZE 57
  24432. +
  24433. +/*
  24434. + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
  24435. + * pattern and if it matches send the next byte as a trigger to sysrq.
  24436. + */
  24437. +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
  24438. +{
  24439. + int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
  24440. + char *p = skb->data;
  24441. +
  24442. + if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
  24443. + !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
  24444. + p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
  24445. + handle_sysrq(p[CO_POS0 + CO_SIZE]);
  24446. +}
  24447. +
  24448. +/*
  24449. * Handle ICMP_ECHO ("ping") requests.
  24450. *
  24451. * RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
  24452. @@ -893,6 +918,11 @@
  24453. icmp_param.data_len = skb->len;
  24454. icmp_param.head_len = sizeof(struct icmphdr);
  24455. icmp_reply(&icmp_param, skb);
  24456. +
  24457. + if (skb->len == ICMP_SYSRQ_SIZE &&
  24458. + net->ipv4.sysctl_icmp_echo_sysrq) {
  24459. + icmp_check_sysrq(net, skb);
  24460. + }
  24461. }
  24462. /* should there be an ICMP stat for ignored echos? */
  24463. return true;
  24464. diff -Nur linux-4.1.6.orig/net/ipv4/sysctl_net_ipv4.c linux-4.1.6/net/ipv4/sysctl_net_ipv4.c
  24465. --- linux-4.1.6.orig/net/ipv4/sysctl_net_ipv4.c 2015-08-17 05:52:51.000000000 +0200
  24466. +++ linux-4.1.6/net/ipv4/sysctl_net_ipv4.c 2015-09-08 23:49:08.461827913 +0200
  24467. @@ -779,6 +779,13 @@
  24468. .proc_handler = proc_dointvec
  24469. },
  24470. {
  24471. + .procname = "icmp_echo_sysrq",
  24472. + .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
  24473. + .maxlen = sizeof(int),
  24474. + .mode = 0644,
  24475. + .proc_handler = proc_dointvec
  24476. + },
  24477. + {
  24478. .procname = "icmp_ignore_bogus_error_responses",
  24479. .data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
  24480. .maxlen = sizeof(int),
  24481. diff -Nur linux-4.1.6.orig/net/mac80211/rx.c linux-4.1.6/net/mac80211/rx.c
  24482. --- linux-4.1.6.orig/net/mac80211/rx.c 2015-08-17 05:52:51.000000000 +0200
  24483. +++ linux-4.1.6/net/mac80211/rx.c 2015-09-08 23:49:08.461827913 +0200
  24484. @@ -3554,7 +3554,7 @@
  24485. struct ieee80211_supported_band *sband;
  24486. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  24487. - WARN_ON_ONCE(softirq_count() == 0);
  24488. + WARN_ON_ONCE_NONRT(softirq_count() == 0);
  24489. if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
  24490. goto drop;
  24491. diff -Nur linux-4.1.6.orig/net/netfilter/core.c linux-4.1.6/net/netfilter/core.c
  24492. --- linux-4.1.6.orig/net/netfilter/core.c 2015-08-17 05:52:51.000000000 +0200
  24493. +++ linux-4.1.6/net/netfilter/core.c 2015-09-08 23:49:08.461827913 +0200
  24494. @@ -22,11 +22,17 @@
  24495. #include <linux/proc_fs.h>
  24496. #include <linux/mutex.h>
  24497. #include <linux/slab.h>
  24498. +#include <linux/locallock.h>
  24499. #include <net/net_namespace.h>
  24500. #include <net/sock.h>
  24501. #include "nf_internals.h"
  24502. +#ifdef CONFIG_PREEMPT_RT_BASE
  24503. +DEFINE_LOCAL_IRQ_LOCK(xt_write_lock);
  24504. +EXPORT_PER_CPU_SYMBOL(xt_write_lock);
  24505. +#endif
  24506. +
  24507. static DEFINE_MUTEX(afinfo_mutex);
  24508. const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly;
  24509. diff -Nur linux-4.1.6.orig/net/packet/af_packet.c linux-4.1.6/net/packet/af_packet.c
  24510. --- linux-4.1.6.orig/net/packet/af_packet.c 2015-08-17 05:52:51.000000000 +0200
  24511. +++ linux-4.1.6/net/packet/af_packet.c 2015-09-08 23:49:08.465827470 +0200
  24512. @@ -63,6 +63,7 @@
  24513. #include <linux/if_packet.h>
  24514. #include <linux/wireless.h>
  24515. #include <linux/kernel.h>
  24516. +#include <linux/delay.h>
  24517. #include <linux/kmod.h>
  24518. #include <linux/slab.h>
  24519. #include <linux/vmalloc.h>
  24520. @@ -698,7 +699,7 @@
  24521. if (BLOCK_NUM_PKTS(pbd)) {
  24522. while (atomic_read(&pkc->blk_fill_in_prog)) {
  24523. /* Waiting for skb_copy_bits to finish... */
  24524. - cpu_relax();
  24525. + cpu_chill();
  24526. }
  24527. }
  24528. @@ -960,7 +961,7 @@
  24529. if (!(status & TP_STATUS_BLK_TMO)) {
  24530. while (atomic_read(&pkc->blk_fill_in_prog)) {
  24531. /* Waiting for skb_copy_bits to finish... */
  24532. - cpu_relax();
  24533. + cpu_chill();
  24534. }
  24535. }
  24536. prb_close_block(pkc, pbd, po, status);
  24537. diff -Nur linux-4.1.6.orig/net/rds/ib_rdma.c linux-4.1.6/net/rds/ib_rdma.c
  24538. --- linux-4.1.6.orig/net/rds/ib_rdma.c 2015-08-17 05:52:51.000000000 +0200
  24539. +++ linux-4.1.6/net/rds/ib_rdma.c 2015-09-08 23:49:08.465827470 +0200
  24540. @@ -34,6 +34,7 @@
  24541. #include <linux/slab.h>
  24542. #include <linux/rculist.h>
  24543. #include <linux/llist.h>
  24544. +#include <linux/delay.h>
  24545. #include "rds.h"
  24546. #include "ib.h"
  24547. @@ -286,7 +287,7 @@
  24548. for_each_online_cpu(cpu) {
  24549. flag = &per_cpu(clean_list_grace, cpu);
  24550. while (test_bit(CLEAN_LIST_BUSY_BIT, flag))
  24551. - cpu_relax();
  24552. + cpu_chill();
  24553. }
  24554. }
  24555. diff -Nur linux-4.1.6.orig/net/sched/sch_generic.c linux-4.1.6/net/sched/sch_generic.c
  24556. --- linux-4.1.6.orig/net/sched/sch_generic.c 2015-08-17 05:52:51.000000000 +0200
  24557. +++ linux-4.1.6/net/sched/sch_generic.c 2015-09-08 23:49:08.465827470 +0200
  24558. @@ -894,7 +894,7 @@
  24559. /* Wait for outstanding qdisc_run calls. */
  24560. list_for_each_entry(dev, head, close_list)
  24561. while (some_qdisc_is_busy(dev))
  24562. - yield();
  24563. + msleep(1);
  24564. }
  24565. void dev_deactivate(struct net_device *dev)
  24566. diff -Nur linux-4.1.6.orig/net/sunrpc/svc_xprt.c linux-4.1.6/net/sunrpc/svc_xprt.c
  24567. --- linux-4.1.6.orig/net/sunrpc/svc_xprt.c 2015-08-17 05:52:51.000000000 +0200
  24568. +++ linux-4.1.6/net/sunrpc/svc_xprt.c 2015-09-08 23:49:08.465827470 +0200
  24569. @@ -341,7 +341,7 @@
  24570. goto out;
  24571. }
  24572. - cpu = get_cpu();
  24573. + cpu = get_cpu_light();
  24574. pool = svc_pool_for_cpu(xprt->xpt_server, cpu);
  24575. atomic_long_inc(&pool->sp_stats.packets);
  24576. @@ -377,7 +377,7 @@
  24577. atomic_long_inc(&pool->sp_stats.threads_woken);
  24578. wake_up_process(rqstp->rq_task);
  24579. - put_cpu();
  24580. + put_cpu_light();
  24581. goto out;
  24582. }
  24583. rcu_read_unlock();
  24584. @@ -398,7 +398,7 @@
  24585. goto redo_search;
  24586. }
  24587. rqstp = NULL;
  24588. - put_cpu();
  24589. + put_cpu_light();
  24590. out:
  24591. trace_svc_xprt_do_enqueue(xprt, rqstp);
  24592. }
  24593. diff -Nur linux-4.1.6.orig/scripts/mkcompile_h linux-4.1.6/scripts/mkcompile_h
  24594. --- linux-4.1.6.orig/scripts/mkcompile_h 2015-08-17 05:52:51.000000000 +0200
  24595. +++ linux-4.1.6/scripts/mkcompile_h 2015-09-08 23:49:08.465827470 +0200
  24596. @@ -4,7 +4,8 @@
  24597. ARCH=$2
  24598. SMP=$3
  24599. PREEMPT=$4
  24600. -CC=$5
  24601. +RT=$5
  24602. +CC=$6
  24603. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  24604. @@ -57,6 +58,7 @@
  24605. CONFIG_FLAGS=""
  24606. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  24607. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  24608. +if [ -n "$RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS RT"; fi
  24609. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  24610. # Truncate to maximum length
  24611. diff -Nur linux-4.1.6.orig/sound/core/pcm_native.c linux-4.1.6/sound/core/pcm_native.c
  24612. --- linux-4.1.6.orig/sound/core/pcm_native.c 2015-08-17 05:52:51.000000000 +0200
  24613. +++ linux-4.1.6/sound/core/pcm_native.c 2015-09-08 23:49:08.465827470 +0200
  24614. @@ -123,7 +123,7 @@
  24615. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  24616. {
  24617. if (!substream->pcm->nonatomic)
  24618. - local_irq_disable();
  24619. + local_irq_disable_nort();
  24620. snd_pcm_stream_lock(substream);
  24621. }
  24622. EXPORT_SYMBOL_GPL(snd_pcm_stream_lock_irq);
  24623. @@ -138,7 +138,7 @@
  24624. {
  24625. snd_pcm_stream_unlock(substream);
  24626. if (!substream->pcm->nonatomic)
  24627. - local_irq_enable();
  24628. + local_irq_enable_nort();
  24629. }
  24630. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irq);
  24631. @@ -146,7 +146,7 @@
  24632. {
  24633. unsigned long flags = 0;
  24634. if (!substream->pcm->nonatomic)
  24635. - local_irq_save(flags);
  24636. + local_irq_save_nort(flags);
  24637. snd_pcm_stream_lock(substream);
  24638. return flags;
  24639. }
  24640. @@ -164,7 +164,7 @@
  24641. {
  24642. snd_pcm_stream_unlock(substream);
  24643. if (!substream->pcm->nonatomic)
  24644. - local_irq_restore(flags);
  24645. + local_irq_restore_nort(flags);
  24646. }
  24647. EXPORT_SYMBOL_GPL(snd_pcm_stream_unlock_irqrestore);
  24648. diff -Nur linux-4.1.6.orig/sound/soc/intel/atom/sst/sst.c linux-4.1.6/sound/soc/intel/atom/sst/sst.c
  24649. --- linux-4.1.6.orig/sound/soc/intel/atom/sst/sst.c 2015-08-17 05:52:51.000000000 +0200
  24650. +++ linux-4.1.6/sound/soc/intel/atom/sst/sst.c 2015-09-08 23:49:08.465827470 +0200
  24651. @@ -368,8 +368,8 @@
  24652. * initialize by FW or driver when firmware is loaded
  24653. */
  24654. spin_lock_irqsave(&ctx->ipc_spin_lock, irq_flags);
  24655. - sst_shim_write64(shim, SST_IMRX, shim_regs->imrx),
  24656. - sst_shim_write64(shim, SST_CSR, shim_regs->csr),
  24657. + sst_shim_write64(shim, SST_IMRX, shim_regs->imrx);
  24658. + sst_shim_write64(shim, SST_CSR, shim_regs->csr);
  24659. spin_unlock_irqrestore(&ctx->ipc_spin_lock, irq_flags);
  24660. }
  24661. diff -Nur linux-4.1.6.orig/virt/kvm/async_pf.c linux-4.1.6/virt/kvm/async_pf.c
  24662. --- linux-4.1.6.orig/virt/kvm/async_pf.c 2015-08-17 05:52:51.000000000 +0200
  24663. +++ linux-4.1.6/virt/kvm/async_pf.c 2015-09-08 23:49:08.465827470 +0200
  24664. @@ -94,8 +94,8 @@
  24665. trace_kvm_async_pf_completed(addr, gva);
  24666. - if (waitqueue_active(&vcpu->wq))
  24667. - wake_up_interruptible(&vcpu->wq);
  24668. + if (swaitqueue_active(&vcpu->wq))
  24669. + swait_wake_interruptible(&vcpu->wq);
  24670. mmput(mm);
  24671. kvm_put_kvm(vcpu->kvm);
  24672. diff -Nur linux-4.1.6.orig/virt/kvm/kvm_main.c linux-4.1.6/virt/kvm/kvm_main.c
  24673. --- linux-4.1.6.orig/virt/kvm/kvm_main.c 2015-08-17 05:52:51.000000000 +0200
  24674. +++ linux-4.1.6/virt/kvm/kvm_main.c 2015-09-08 23:49:08.465827470 +0200
  24675. @@ -218,7 +218,7 @@
  24676. vcpu->kvm = kvm;
  24677. vcpu->vcpu_id = id;
  24678. vcpu->pid = NULL;
  24679. - init_waitqueue_head(&vcpu->wq);
  24680. + init_swait_head(&vcpu->wq);
  24681. kvm_async_pf_vcpu_init(vcpu);
  24682. page = alloc_page(GFP_KERNEL | __GFP_ZERO);
  24683. @@ -1779,7 +1779,7 @@
  24684. void kvm_vcpu_block(struct kvm_vcpu *vcpu)
  24685. {
  24686. ktime_t start, cur;
  24687. - DEFINE_WAIT(wait);
  24688. + DEFINE_SWAITER(wait);
  24689. bool waited = false;
  24690. start = cur = ktime_get();
  24691. @@ -1800,7 +1800,7 @@
  24692. }
  24693. for (;;) {
  24694. - prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  24695. + swait_prepare(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
  24696. if (kvm_vcpu_check_block(vcpu) < 0)
  24697. break;
  24698. @@ -1809,7 +1809,7 @@
  24699. schedule();
  24700. }
  24701. - finish_wait(&vcpu->wq, &wait);
  24702. + swait_finish(&vcpu->wq, &wait);
  24703. cur = ktime_get();
  24704. out:
  24705. @@ -1825,11 +1825,11 @@
  24706. {
  24707. int me;
  24708. int cpu = vcpu->cpu;
  24709. - wait_queue_head_t *wqp;
  24710. + struct swait_head *wqp;
  24711. wqp = kvm_arch_vcpu_wq(vcpu);
  24712. - if (waitqueue_active(wqp)) {
  24713. - wake_up_interruptible(wqp);
  24714. + if (swaitqueue_active(wqp)) {
  24715. + swait_wake_interruptible(wqp);
  24716. ++vcpu->stat.halt_wakeup;
  24717. }
  24718. @@ -1930,7 +1930,7 @@
  24719. continue;
  24720. if (vcpu == me)
  24721. continue;
  24722. - if (waitqueue_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  24723. + if (swaitqueue_active(&vcpu->wq) && !kvm_arch_vcpu_runnable(vcpu))
  24724. continue;
  24725. if (!kvm_vcpu_eligible_for_directed_yield(vcpu))
  24726. continue;